How to run a script on shut down

Ray Parrish crp at cmc.net
Wed Nov 26 20:46:54 UTC 2008


Paul Johnson wrote:
> On Tue, Nov 25, 2008 at 11:17 PM, Ray Parrish <crp at cmc.net> wrote:
>   
>> Hello,
>>
>> I have a script I've written which checks to see if my web site is down,
>> and warns me when it isn't working. It depends on another script to stop
>> it's inner loop, by deleting a file called go.txt from it's working
>> directory in order to shut it down by stopping the loop.
>>
>> I can start the web monitoring script from Preferences, Sessions by
>> adding a call to it there, but I don't know where to put a corresponding
>> call to the stop monitoring script so it will run when I log off, or
>> shut down. I'd really like to find out, as this script does the final
>> log file clean up for the application so I have to run it manually
>> before I log off or it won't clean up the log files.
>>
>> Anyone know how to do this?
>>
>>     
>
> The function at can be used to schedule
> actions in the future.  You can use atq to see future actions and atrm
> to remove them.  I'd suggest you revise your program a bit to use at
> to schedule future checks.  If you shut off while events are waiting,
> there's no damage.  You can use at in a script that refers to itself,
> so that if you run the script once, it does its work and then puts
> itself in the schedule for later.  So if you just write your script so
> it clean up when starts, then wouldn't everything "just work".
>
> Here's a script I use to change the backgrounds every 15 minutes. It
> is called "compizChanger.sh".  Note the last line calls itself to run
> again.
>
> pjcompizbackground.pl -w 1 -W 1 -d /usr/share/backgrounds
> pjcompizbackground.pl -w 2 -W 1 -d /usr/local/share/Backgrounds
> at -f /home/pauljohn/bin/compizChanger.sh NOW + 15min
>
> Well, you can tell I'm on vacation and have plenty of time to waste :)
>
> HTH
>
> PJ
>
>
>
>   
LOL! Yes, that was quite a bit of information! Thank you! I like your 
last idea as it doesn't involve cron which I can't figure out how to use 
yet. [mostly due to laziness about looking for a better reference than 
the cryptic man page]

I've looked over my script again, and realized that it doesn't really 
need any cleanup as it's taken care of in the main script. No matter 
when I stop it, it will already have written new entries to the daily 
log, and the only other thing that could happen is, if the web site was 
down there would be a left over file noting this condition, which gets 
deleted the first time it is found after a successful check of the web 
site, so no problem there either.

I'm going to re-write to use the at command to recall the script. Thanks 
again for the tip!

Later, Ray Parrish

-- 
http://www.rayslinks.com/ Web index of human reviewed links.
<http://www.rayslinks.com/Troubleshooting%20and%20fixing%20Windows.html>
Trouble shooting and Fixing Windows
http://www.writingsoftheschizophrenic.com My poetry in web pages





More information about the ubuntu-users mailing list