[Gllug] Automatic shutdown script
Dylan
dylan at dylan.me.uk
Sat Sep 6 15:52:32 UTC 2003
Hi all,
I'm taking my first serious plunge into bash. I want to make the server and
gateway machines on my home LAN shutdown when they are not needed. I figure I
can do this:
Set up a cron job on the server which executes a script to do (roughly) the
following:
Check for lock file
if file exists then
exit
otherwise
create it
loop through a set of defined hosts
if one or more responds to a ping
record an active response
if there was an active host
check if there was an active host on the last run
if there was no active host on this run and no active host on the last run
record state
tidy up
shutdown
if there was no active host this time but there was one last time
record state
tidy up
exit
if there was an active host this run and last run
record state
tidy up
exit
Clearly this is still at the conceptual stage. My questions are:
How should I discover the hosts to ping? The server's /etc/hosts file is kept
current (for sharing over NIS) so I figure that's the best place to get the
info. I can easily define a numerical IP range to cover the hosts in the
script (any one between 192.168.0.2 and 192.168.0.200 inclusive) or add
comments to the hosts file to tell the script what to do. Or maybe I could
create a set of aliases (say pingtest1, pingtest2) which the script could
then just use somehow.
I figure recording the result of the ping test can be stored in a variable -
but I'm not clear on the difference between 'shell variable' and 'local
variable'.
Recording the final state (i.e. whether the run resulted in no response or
not) needs to persist from one run to the next, so is that best recorded in a
state file or as an environment variable?
Any other comments...?
TIA
Dylan
--
Sweet moderation
Heart of this nation
Desert us not
We are between the wars
- Billy Bragg
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list