Created
June 13, 2019 19:46
-
-
Save bjoerns1983/4d5c7a8ded5cb9a2e1ffac18f38071a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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