I have one doubt on trap!!

Gurus of UNIX,

There ia a script which loads some data within a box..... (what type of data is not important) ...... this script may complete in one hour, two hour or may be one day.............

My problem is if system goes panic and reboots then I need a mail which gives me the status of the script............ Like the scirpt got completed or Script was in progress and got killed......... so that I can rerun the script manually ........ I need your help and advice as how to trak this....

If no one minds can anyone give me an example script for the above scenario? :o

Immediate reply is most appreciated... :cool:

Regards,
Vangalli

Hi Folks,

Use this below code in your all shell scripts to trap the error signals when anything goes wrong during execution.

#!/bin/bash

function error_trap
{
echo "Program killed" | mailx -s "Error Signal trapped" emailid@ford.com
}

trap error_trap 1 2 3 4 5 6 7 8 9 10 11

sleep 7000

Thanks
Babu

I wrote this script ....

#!/bin/ksh
function test
{
sleep 20
echo " I am Done!!" >> ~/main.log
}

function trap_it {
echo "SCRIPT INTERUPPTED!!" >>~/trap.log
exit 2
}
trap 'trap_it' 1 2 3 4 5 6 7 8 9 10 12 13 14 15 20
test

When i issue kill -9 <PID> it wont trap -9 and when
i give CTRL-C it traps and i can see the message SCRIPT INTERUPPTED!! in trap.log ............. but when server goes down it wont..... Please advice on this as i need to complete this activity by next two hours.....

Regards,
Vangalli

I don't think we can set signal handlers for SIGKILL and SIGSTOP.

Thanks
Nagarajan G

this works if the main script gets killed by kill -9 or CTRL-C ......... but if system gets rebooted while the script is running ..... and during this interruption no mail is sent to us. that prgramm killed or interuppted.... any idea or some work around.....?