[Solved] /usr/sbin/wol scripting problem

Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware
Author Message
wuhtzu
DD-WRT User


Joined: 05 Sep 2011
Posts: 50

PostPosted: Tue Aug 28, 2012 16:21    Post subject: [Solved] /usr/sbin/wol scripting problem Reply with quote
Note: What was initially thought to be some scripting mistake turned to be completely wrong. It seems to be a strange behavior of the computer receiving the magic packet. I have found that it's only one particular machine which behaves in this way. See reply #1 for more details.

Hi everyone

As a part of a larger, more advanced auto wake-on-lan project I am trying to write a small shell script which will just ping a given ip and send a magic packet (using /usr/sbin/wol) if there is no reply.

My problem is that 2/3 times I begin a test session (calling the script and watch for a certain computer to wake up) I end up seeing the correct output from my shell script (i.e. the output from /usr/sbin/wol redirected to a file) but the computer does not wake. These unsuccessful executions of the script I've seen happening up to 10 times in a row.

This is the script:
Code:
#!/bin/sh

logfile=/var/log/autowol

if ping -q -c 1 -W 1 $1 > /dev/null; then
    echo `date +"%Y-%m-%d %H:%M:%S"` "  $1 ($3) already awake, no wol package sent" >> $logfile
else
    echo `date +"%Y-%m-%d %H:%M:%S"` "  $1 ($3) not awake, wol package sent" >> $logfile
    /usr/sbin/wol -i $2 -p 9 $3 >> $logfile
    echo $? >> $logfile
fi


It simply pings the remote machine, directs the ping output to /dev/null and if the ping command exits with status 0 (success/reply received) a simple "already a wake" message is logged. If the exit status is not 0 (no reply received) it will call /usr/sbin/wol and log a "sending magic package", output of /usr/sbin/wol and exit status of /usr/sbin/wol to the logfile.

In my logfile I will see entries like the ones below even when the computer does not wake. The first line is my own little message, second line is the output from /usr/sbin/wol and the third line is the exit status of /usr/sbin/wol.

Code:
2012-08-28 18:00:58   10.0.1.147 (00:22:4D:82:28:30) not awake, wol package sent
Waking up 00:22:4D:82:28:30...
0
2012-08-28 18:01:15   10.0.1.147 (00:22:4D:82:28:30) not awake, wol package sent
Waking up 00:22:4D:82:28:30...
0
2012-08-28 18:04:14   10.0.1.147 (00:22:4D:82:28:30) not awake, wol package sent
Waking up 00:22:4D:82:28:30...
0


The output, to me at least, indicates (maybe even proves) that /usr/sbin/wol is actually run/called and it exits normally. Yet sometimes (up to 10 times in a row) the remote machine does not wake, other times it does.

This is how it usually goes down:
  1. The script fails to wake the machine for some reason.
  2. I check the /var/log/autowol file and find an entry clearly indicating that the /usr/sbin/wol utility has been called and exited successfully
  3. I wait maybe 20-30 seconds and invoke the script again
  4. The log shows the same thing as before; an successful unvocation. Yet the machine did not wake.
  5. I repeat this 3-10 times with the same result (waiting 30sec to 5min between invocations)
  6. I break the unsuccessful row of tries by invoking the script two times quickly after one another (only 5-10 sec) and the computer wakes.


It is important to note that the script is successful from time to time and, as far as I've found, always when invoked twice quickly.

It is also important to note that I have _not_ been able to reproduce this behavior by calling /usr/sbin/wol directly from the shell. These invocations will always work it seems. That is what leads me to believe I am doing something stupid in my script.

Any thoughts are more than welcome!

Thanks,
Wuhtzu
Sponsor
wuhtzu
DD-WRT User


Joined: 05 Sep 2011
Posts: 50

PostPosted: Wed Aug 29, 2012 15:42    Post subject: Reply with quote
So this was not a scripting problem after all, it is a strange behavior of one particular machine. Upon testing the script against other machines on the same network the behavior could not be replicated at all.

Sadly I only tried waking another machine after spending hours looking at logs from tpcdump. These confirmed that the magic packet was being sent but for some reason not acted upon by the receiving machine.

I found that as little as this code would produce the result of this particular machine not being woken by the magic packet unless the script was run twice within a certain period of time:

Code:

#!/bin/sh
ping -c 1 -W 1 $1
/usr/sbin/wol -i $2 -p 9 $3


It turns our that if the script is invoked twice with with more than 80 seconds between invocations the machine would never wake. On the other hand, invocations with less than 70 seconds between them would always wake the machine upon second invocation.

I guess this has be to some funny behavior / bug on the nic receiving the magic packages. The machine in question is based on an Intel DQ67SW motherboard and the NIC in use is the one included on the motherboard (Intel 82579LM).

/ Wuhtzu
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum