Skip to content

Instantly share code, notes, and snippets.

@bjoerns1983
Created June 13, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerns1983/4d5c7a8ded5cb9a2e1ffac18f38071a0 to your computer and use it in GitHub Desktop.
Save bjoerns1983/4d5c7a8ded5cb9a2e1ffac18f38071a0 to your computer and use it in GitHub Desktop.
#!/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