Combining Wake-on-lan and Opening a Terminal

Combining Wake-on-lan and Opening a Terminal to a remote system

In my continuing quest to automate repetitive system tasks I have combined Wake-On-Lan with my remote-console command.
I have a remote machine that I remotely startup using  wake-on-lan. And this is something I use most days. I ususally connect to the system via an ssh session. My shortcut to the terminal is now linked to a script that checks if the system is awake, and if notsends the wol commands and wait untill it can see the system then finally launches the terminal.

The terminal has a differant profile to remind me it is a remote session.(to try to stop me rebooting the wrong system)

The script IS a bit hack and it could be greatly improved. If you try and use it there are a few extras you may need to install. (fping wake-on-lan and on some system zenity)

#!/bin/bash
#jont@ninelocks dogs dinner script, nasty but it works...
#need to add incheck for if terminal connected or something....
#130612 should really add check for fping being installed
#below wakehost calls a wakeonlan script for the host
#blah is the name of a terminal profile
host="192.168.1.99"
COUNT=0
alive=0
fping -u $host >& /dev/null
if [ $? -ne 0 ]; then
		(while [ $COUNT -lt 100 ]; do
			echo $COUNT
			let COUNT=COUNT+5
			wakehost.sh
			sleep 20
			fping -u $host >& /dev/null
			if [ $? = 0 ]; then
				$alive=0
				break;
			fi

			done ) | zenity --progress --auto-close
fi
if [ $alive = 0 ]; then
#gnome-terminal --window-with-profile=blah
mate-terminal --window-with-profile=blah -e "ssh host"
fi

class HelloWorld {    public static void main(String[] args) { System.out.println("Hello World!");    } }

zenity to provide the dialog box, fping to provide a ping service thats script friendly.

The terminal line will vary depending on your system. The one shown was for a mint based system…. and yes it could be greatly improved, but it works enough to do what I need at the moment, ymmv 🙂

This entry was posted in computing, linux and tagged . Bookmark the permalink.

Comments are closed.