Here is a Scritp script that wakes a computer from sleep mode, waits until it have turned on by pinging it, and runs a program when its up.
You must download wolcmd before using this script, and place the wolcmd.exe file in the same folder where the script bat file is placed.
Save the code as a bat file, for example script.bat using notepad, and edit the following variables:
@echo off::You can change the follwing varibles, but don't add spaces before or afterset macaddress=123456789ABCset ipaddress=192.168.2.20set subnetmask=255.255.255.0set wolport=9 set exit_timer=0set program_to_start_path=notepad.exe :network_connection(ipconfig | find "IPv4") || goto no_network :wakewolcmd %macaddress% %ipaddress% %subnetmask% %wolport%echo Waiting for computer to wake up:echo(:doping(ping %ipaddress% -n 1 | find "TTL=") || goto wakeecho(echo ============================================echo Target (%ipaddres%) is up!!!echo ============================================goto end:no_networkecho There is no network connection! :endTIMEOUT /T %exit_timer% /NOBREAKstart "" "%program_to_start_path%"The variables you need to change on the Linux bash script are similar, however you need to write your own commands at the end of the script.
Also, you need to install "wakeonlan" before running this script, by entering the following command in the terminal:
sudo apt-get install wakeonlan#!/bin/bash#here are the varibles you need to changeipaddress=192.168.2.20subnetmask=192.168.2.255macaddress=a0:d3:c1:47:12:b4wolport=9#start of the scriptecho Trying to wake $ipaddresshost_up=0wakeonlan -i $subnetmask -p $wolport $macaddress sleep 1while (($host_up == 0))do if ping -c 1 $ipaddress &> /dev/null then echo $ipaddress is up! host_up=1 else wakeonlan -i $subnetmask -p $wolport $macaddress echo -n "." sleep 1 fidoneif (($host_up == 1)); then #enter you commands here echo "Hello world"fi