I am running this script from my router (DD-WRT) to test if any known clients are awake on the network so that I can wake up the file server if they are on. I also need to test if the file server is awake on the network, if it is already on, then I obviously don't need to wake it up. I'm running this from cron but I don't think that is overly important as the if statement isn't passing/failing properly for me.
If the machines are on and the file server is off -> I need to WOL the file server
If the machines are on and the file server is on -> I can just exit
If the machines are off and the file server is on (or off) -> I can just exit (the file server will turn itself off when machines are not available)
The three known clients I'm looking for are 192.168.2.99, 192.168.2.50, and 192.168.2.60. The file server is 192.168.2.5.
With the code below, the WOL packet is always being sent (even if the file server is already on).
- Code: Select all
if [ "`ping -c 3 -w 3 192.168.2.99 | wc -l`" -gt 6 -o "`ping -c
3 -w 3 192.168.2.50 | wc -l`" -gt 6 -o "`ping -c 3 -w 3 192.168.2.60 | wc -l`" -
gt 6 -a "`ping -c 3 -w 3 192.168.2.5 | wc -l`" -lt 6 ]; then /usr/sbin/wol -i 19
220.127.116.11 -p 7 00:0A:E4:89:B7:DE; fi
Basically by pinging the hosts I'm counting the lines returned by the ping command. When a machine is successfully ping'd there are 8 lines and unsuccessful there are 4.
But like I said, it's not working. Please help.