FreeBSD下自动检查网卡状态并自动启用网卡
By admin
- One minute read - 71 words#/bin/bash
log_file=`date +%Y%m%d`
log_file=$log_file".log"
check_date=`date +%H:%M:%S`
#status=`ifconfig bge0 | grep status | awk '{print $2}'`
status=`ifconfig bge0 | awk '/status/{print $2}'`
if [ $status != 'active' ]; then
status='down'
ifconfig bge0 up
else
echo 'ok'
fi
check_date=${check_date}" =========== "${status}
echo $check_date >> $log_file
另一处写法,其实一样的:
#!/bin/bash
log_file="$(date +%Y%m%d).log"
status=$(ifconfig bge0 | awk '/status/{print $2}')
if [ "X${status}" != "Xactive" ]; then
ifconfig bge0 up
fi
echo "$(date +%H:%M:%S) ===== ${status}" >> $log_file