trap

Hi

At the beginning of my script, i will create a file and at the end of the script i will delete that.

But i got to delete the file even if the process is forcefully killed, or server is rebooted...

I think i can make use of trap signal, but couldnt figure out how and where to use in my script.

What will be structure of the command?

trap cannot "trap" all signals, for example SIGKILL is "immune" to a trap.

Near the top of your file:

#!/bin/ksh

trap "rm -f somefile; exit 1" INT  # you can add more signals here

will execute the command in quotes when CTRL/C -- SIGINT -- is sent to the process.
kill -l (that's the letter ELL) will show you the names of your signals. Be aware that not all signals need to be trapped nor can they be.

If it's bash or ksh (maybe others too) you can use 'trap something 0', which will run on the virtual "EOF" signal.

pludi is helpfully pointing out - you ought know that it is possible to make your trap statement do the cleanup on exit - in ksh anyway, I dunno about bash.

trap "rm -f somefile; exit " 0 INT QUIT SEGV BUS

Thankyou.
But what does 1 indicate. Is that the numeric form of signal.
Where can i find the other numeric forms of signals.