Skip to content

Instantly share code, notes, and snippets.

@bjoerns1983
Created June 13, 2019 19:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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