Originally Posted by
ov3rcl0ck
Shell scripts are too high level to catch SIGTERM or SIGKILL. Maybe theres a way to do it, but I don't think trapping a signal will do it, seeing as the signal is sent to BASH/shell rather than your script. Unless BASH will relay this information to a shell script, which I don't think it does.
Wrong!
Here's an example script where SIGTERM is caught:
Code:
#!/bin/bash
trap dothis SIGTERM
function dothis()
{
echo "Revert to original wallpaper here."
exit 0
}
while [ true ]
do
sleep 2
done
Run this script, then after referencing the PID of the script, issue a SIGTERM signal to it with something like:
Code:
kill -15 <pid>
# or
kill -s SIGTERM <pid>
To get a list of all of the signals that are recognized by Bash, run Obviously, as mentioned earlier, SIGKILL cannot be intercepted.
Bookmarks