I would like to run certain aliases and simple commands when system shuts down or reboots or when I simply log out of system. This would help a lot as I usually forget about shutting down vagrant ( vagrant halt ) and some other terminal commands. Do we have some kind of bash files or scripts so I can achieve this on Ubuntu 14.04.
Asked
Active
Viewed 1,442 times
3
-
Take a look here: http://askubuntu.com/questions/814/how-to-run-scripts-on-start-up – LnxSlck Oct 14 '14 at 13:08
-
2Check the answers of http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot (duplicate?) – elgicse Oct 14 '14 at 13:10
1 Answers
-1
Runlevel 0 corresponds to shutdown, and Runlevel 6 corresponds to reboot.
The /etc/rc[0-6].d/ directories contain scripts that are executed when a particular runlevel is initiated.
So you can write a script that contains commands to shutdown various processes, and store that script in /etc/rc0.d/K99_yourscript and make it executable. This will run your script at shutdown. Copy the script over to /etc/rc6.d/K99_yourscript to have it execute on reboot as well.
-
This is not the recommended way to manage System V init scripts. For an overview on the topic read
/etc/init.d/README
andupdate-rc.d(8)
. – David Foerster Oct 14 '14 at 20:39