Reputation: 111
I'm writing a script which I want to run before every shutdown of my ubuntu system. I have placed my script named myscript inside /etc/init.d folder and then created symbolic links in rc0.d and rc6.d as K01myscript and S01myscript in rc5.d. But the problem is that the script is not running at all.
My Script @paxdiablo -
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LOGPATH=/home/user/Documents
lockfile=/var/lock/subsys/decomission
now=$(date +'%T')
start() {
touch $lockfile
echo "[$now] System startup" >> $LOGPATH/test.log
}
stop() {
echo "[$now] System shutdown" >> $LOGPATH/test.log
rm -f $lockfile
}
status() {
echo "[$now] Hi, you're checking status" >> $LOGPATH/test.log
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
Upvotes: 1
Views: 917
Reputation: 13
This question is old but I was working on these lines today, so just wanted to check, did you add the script/service to run under init. You need to check the output of chkconfig --list
I guess. If it's not listed then it's not configured to execute by the init system. For example:
[testfolk@jomohost ~]$ sudo chkconfig --list|grep myscript
myscript 0:off 1:off 2:on 3:on 4:off 5:on 6:off
Upvotes: 1
Reputation: 4154
At the beginning of the script you must set the PATH, for example:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Upvotes: 0