return to Computers page


Remotely controlling a UNIX or LINUX server,
via email messages.


The server must be running an email transport program, such as SENDMAIL or PROCMAIL



1. create checkmail.sh as follows:

#!/bin/sh
until [ 1 -eq 2 ]; do
   `cat /var/spool/mail/username | grep Command | awk '{print $2};'`
sleep 5
done

what #1 does:
Until 1 equals 2 (which is never, let's hope) do the following -
   Check the username mail box, look for a line with the word "Command" in it,
  
take the 2nd word in that line, and run it
   sleep for 5 seconds, and repeat



2. run the checkmail.sh program as root:

# sh checkmail.sh



what #2 does:
Runs the program created in 1.
If it is run as root, then it will have the necessary privileges to do things such as "reboot"




3. send username@mydomain.com an email with the subject line Command reboot


what #3 does:
When an email is sent to username@mydomain.com, it will be received by SENDMAIL (or whatever),
and end up in /var/spool/mail/username.
Within 5 minutes, the checkmail.sh program will find it and execute the command.


In this case, the system would be rebooted remotely.








return to top
home

Copyright © 1999-2006 billhance.com.  All rights reserved.