I want to call a script on machine shutdown and restart. I have written code like
#! /bin/bash
#chkconfig: 0 6 1 1
#description: Description of the script
# processname: killfoo
# this script starts and stops foo
# Some things that run always
LOG_FILE="/tmp/killfoo.log"
log() { while IFS='' read -r line; do echo "$(date) $line" >> "$LOG_FILE"; done; };
exec > >(tee >(log))
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Nothing to done"
;;
stop)
echo "Stopping script killfoo"
pkill -9 foo >> $LOG_FILE 2>&1
;;
*)
echo "Usage: /etc/init.d/killfoo {stop}"
exit 1
;;
esac
exit 0
I created file /etc/init.d/killfoo having executable permission. I have enable this script for run level 0,6.
chkconfig --add killfoo
chkconfig --level 6 killfoo on
But script is not getting executed on machine restart. What could be the problem ?