Looking your script, I guess it is logically correct. However, you must get a syntax error in the line:
The character "[" is a symbolic link to /usr/bin/test. If you read "man test", you'll see:
1 - when using the alternative "[" "]" you have to separate both the brackets by space;
2 - numerical comparisons are specified by "-eq" for "equal to", "-neĻ for "not equal to".
So, this line should be:
if [ $? -ne 0 ]; then
I don't know the "wol" command but, the syntax is the same as you use in interactive mode.