cfanbo / cfanbo.github.io

1 stars 0 forks source link

FreeBSD下自动检查网卡状态并自动启用网卡 | 学习笔记 #243

Open cfanbo opened 10 months ago

cfanbo commented 10 months ago

https://blog.haohtml.com/archives/11827

/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