Pete's Linux Advent Calendar 2007

The 5th day

Signal Handling in Scripts

Here's how to write a shell script that re-reads it's configuraiton on sighup. The configuration file might define a variable:
MYVAR=1
Save this as config. The script just sources this file and prints it's value:
#!/bin/bash
. config
trap '. config' 1
echo send a SIGHUP to this pid: $$
while :; do
    echo $MYVAR
    sleep 1
done
Run this script and modify the value of MYVAR in the config file. Then run "kill -1 <pid>". You will notice that the value printed to stdout has changed accordingly.
Pete's Linux Advent Calendar 2007

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram