If you want to wakeup remote machine over a LAN and automatically start the remote desktop viewer this is a solution.
The script first send a magic package to wakeup the remote machine. After that is checking every 4 second is the remote desktop is available on the machine. This done by telnet-ting to port 5900.
If the port 5900 is reachable then the (local) remote desktop viewer is launched.
#!/bin/bash
###########################################################
# Verion 1.2
#
# This script sends a magic package to wakeup the MCE
# over LAN
#
# 24-10-2008 by Rob Groen
#
# And starts the Remote Desktop Viewer GUI client
#
###########################################################
###########################################################
# CONFIG THIS
#
###############
# HOST
# Replace [HOSTNAME OR IP-ADDRESS] with the hostname or
# ip-address of the remote machine.
#
# HOST = mediacenter.local.net
# HOST = 192.168.1.151
HOST=[HOSTNAME OR IP-ADDRESS]
################
# PORT
# The port on the remote machine where is looks for remote connections
# Standard is this 5900
#
# Port = 5900
PORT=5900
###############
# MAC
# This is the MAC-address from the remote machine ethernet card.
# You can find this with the command ifconfig
#
# MAC=00:13:D4:E8:C6:F3
MAC=[MAC ADDRESS FROM REMOTE LAN ADAPTER]
###########################################################
#DO NOT EDIT UNDER HERE
###########################################################
# Wake up MCE
wakeonlan $(echo $MAC)
# Number of times we are goning to try is we can ping the host.
COUNTER=100
# A loop
while [ $COUNTER -gt 0 ]
do
# See if we can make a telnet connection
# to the host (MCE in this case)
echo ${COUNTER} telnet ${HOST} ${PORT}
{
telnet ${HOST} ${PORT} << _EOF_
exit
_EOF_
} > /tmp/telnet.$$.txt
# See is we got a "0" as result from the telnet command.
if (! grep -q 'Connected' /tmp/telnet.$$.txt); then
# If it is 0 than it's not OK.
echo ${HOST}:${PORT} $(date '+%Y-%m-%d %H:%M:%S') Connection Unavailable
else
# Open a remote desktop viewer
# and a connection to MCE
vinagre mce:5900 --name=MCE-automatic
# set counter to zero to quit the while loop
let COUNTER=0
fi
# Subtract one from the counter so the number
# of times the while loop has to go is one less
let COUNTER=COUNTER-1
# wait a while
sleep 4
# remove the temp file
[ -f /tmp/telnet.$$.txt ] && rm /tmp/telnet.$$.txt
done
exitI made a menu item with a "Wake Up MCE" icon so it look nice on my desktop. See attached files.
