Ubuntu 14.10 rc.local / rc0.d debugging / test scripts

Debugging rc.d scripts can be a pain. These two scripts might help you to get a better idea on what is going on.

Note: replace $USER with your username.

Starting up

Save the following lines as /etc/init.d/custom-startup.sh

#!/bin/bash
LOGFILE="/var/log/custom-start.log"
TIMESTAMP=$(date +"%F %H:%M:%S")
rm $LOGFILE
exec 2>> $LOGFILE
echo $TIMESTAMP >> $LOGFILE
echo -e '\nnext command: ls /' >> $LOGFILE
ls / >> $LOGFILE
echo -e '\nnext command: ls /home' >> $LOGFILE
ls /home >> $LOGFILE
echo -e "\nnext command: ls /home/$USER/Desktop" >> $LOGFILE
ls /home/$USER/Desktop >> $LOGFILE

Set the file as executable:
sudo chmod +x /etc/init.d/custom-start.sh

Add this line to /etc/rc.local before “exit 0”
/etc/init.d/custom-startup.sh

Shutdown

Save the following lines as /etc/init.d/custom-shutdown.sh

#!/bin/bash
LOGFILE="/var/log/custom-exit.log"
TIMESTAMP=$(date +"%F %H:%M:%S")
rm $LOGFILE
exec 2>> $LOGFILE
echo $TIMESTAMP >> $LOGFILE
echo -e '\nnext command: ls /' >> $LOGFILE
ls / >> $LOGFILE
echo -e '\nnext command: ls /home' >> $LOGFILE
ls /home >> $LOGFILE
echo -e "\nnext command: ls /home/$USER/Desktop" >> $LOGFILE
ls /home/$USER/Desktop >> $LOGFILE

Set the file as executable.
sudo chmod +x /etc/init.d/custom-shutdown.sh

Add a symlink to call the script:
sudo ln -s /etc/init.d/custom-shutdown.sh /etc/rc0.d/K04custom-shutdown.sh

After a restart of the system you can check the logfiles:
cat /var/log/custom-exit.log
cat /var/log/custom-start.log