Cleaning up after a script on shut down
Heike C. Zimmerer
nospam08q2 at gmx.net
Tue Aug 25 11:08:02 UTC 2009
Oliver Grawert <ogra at ubuntu.com> writes:
> hi,
> Am Sonntag, den 23.08.2009, 16:22 -0700 schrieb Ray Parrish:
>
>> I just need to remove two files on shutdown, but their names change with
>> the PID of the script.
>
> if its a shell script, use the trap call at the top of your code, it
> will automatically run the cleanup function if it catches one of the
> listed signals (1 2 3 6 9 15):
>
> --- snip ---
>
> trap cleanup 1 2 3 6 9 15
>
> cleanup(){
> ...
In bash, you can set a trap on exit:
cleanup(){
... cleanup code ...
}
trap cleanup EXIT
This will catch all possible reasons for exit, including notmal return
and signals other than the ones you named.
Heike
More information about the ubuntu-users
mailing list