[K12OSN] OT: Shutdown Linux from Windows?

Doug Simpson veewee77 at alltel.net
Wed Sep 6 03:55:26 UTC 2006


See note about ping. . .
Doug Simpson wrote:

> OK,
> I worked this out myself:
>
> In the /etc/rc.local file (or wherever your local init scripts live) 
> start a ping when the server starts up that pings the winders box you 
> wish to be the "controller" like this:
>
> ping -i 60 server.to.ping. >>/var/log/pingreplys

Don't forget the & at the end of the above line. . . Should read:
ping -i 60 server.to.ping. >>/var/log/pingreplys &

That makes the ping detach and doesn't hang the cron job. . .

> Use the IP if you have a static one on the winders computer. The lower 
> the -i, the better the time resolution, but the bigger the pingreplys 
> file and the slower grep will parse it. -i -60 means it will ping 
> every 60 seconds, meaning the minimum time between the winders box 
> going down and the linux one going down will be at least 60 seconds. 
> and the maximum will be the interval between the cron run of the 
> script, plus 60 seconds.
>
> Once this is started, it will ping and add the results to 
> /var/log/pingreplys.
>
> Now, set a cron job that runs the following script at whatever 
> interval you want, I recommend not more that about every 5 minutes but 
> you can use whatever you want. Name the script whatever yoiu want, 
> make it executable and point the cron job to it and execute it as 
> root. It can live wherever you want it to.
> You may have to adjust the paths in the script depending on where 
> things live for your distribution.  It was tested and works on FC3.
>
> If your BIOS supports the turn-on at such time feature, You could make 
> the server boot every day at the same time. If the winders box is not 
> on, the server will determine that and shut itself right back off 
> until the next day. If the winders box is on, it will reply and the 
> linux server will stay up. This will work, for example, on weekends 
> when there is no one in the office (or wherever the winders box is).
>
> Hope this is close to what you wanted!
>
> ----Begin Script-----
>
> #!/bin/bash
> # The following function lines set up functions to be used later.
> function Online {
>        exit
> }
> function Off {
>        /bin/rm -f /var/log/pingreplys ;
>        /sbin/shutdown -h now
> }
> #The following line examines the file /var/log/pingreplys for the
> #string "Unreachable" and counts the occurrences of "Unreachable".
> #It stores the value in C1.
> #
> C1=`grep Unreachable /var/log/pingreplys -c`
> #
> # The following line determines if "Unreachable" was found. If not, the
> # script just exits.
> #
> if [ $C1 -eq 0 ];
>        then Online
> fi
> # The following line determines if there *is* an "Unreachable",
> # meaning that the other computer is offline and then shuts down
> # this server. The actual power-off depends on -h working with your
> # particular motherboard. If "shutdown -h now" causes it to turn itself
> # "off" then this script will work.
> if [ $C1 -gt 0 ];
>        then Off
> fi
>
>
> -----End Script-----
>
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
>




More information about the K12OSN mailing list