Macアドレスでwifi接続の接続状態をログに記録するbashスクリプトを作成しようとしていますが、コードの構文に問題があります。
#!/bin/sh
client="E1:FA:41:23:00:AC"
logfile="/var/logs/wificonn.log"
timestamp=$(date +"%Y%d%m %T")
assoclist=$(wl assoclist | grep $client)
loglast=$(tail -n 1 $logfile | grep $client Not Connected)
notconnmsg="$timestamp $client Not Connected"
connmsg="$timestamp $client Connected"
if [ ! -f $logfile ]; then
touch $logfile
fi
if [ -z $assoclist ]; then # Client is not connected
if [ -n $loglast ]; then # Last log is connected show not connected message
echo $notconnmsg
echo $notconnmsg >> $logfile
fi
else # Client is connected
if [ -z $loglast ]; then # Last log is not connected show connected message
echo $connmsg
echo $connmsg >> $logfile
fi
fi
これは60秒ごとにcronジョブとして実行され、反対のことが当てはまる場合にのみ、接続されたイベントまたは接続されていないイベントを表示/ログに記録する必要があります。私は最後のログエントリをチェックすることによってこれを達成しようとしています。たとえば、最後のログが接続されておらず、現在接続されている場合は、ファイルに記録します。ここに問題があります。
ありがとう