Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
macadress="XX:XX:XX:XX:XX:XX"
ip="XXX.XXX.XXX.XXX"
logfile="/var/log/nginx/site_access.log"
tail -n1 -F $logfile | while read line
do
user=$(echo $line | cut -d " " -f3)
scode=$(echo $line | cut -d " " -f9)
if [ $user != "-" ] && [ $scode != "401" ]
then
echo "Ping Server"
ping -c 1 -w 1 -q $ip >/dev/null
status=$?
if [ $status -ne 0 ]
then
echo "Wake Server"
/usr/sbin/etherwake -i enp3s0 "$macadress"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment