Run Shell Script on Ubuntu Shutdown
I'm trying to execute a shell script when Ubuntu shuts down (halt) or reboots. I've gotten a script to run when I boot Ubuntu (sudo update-rc.d my开发者_JAVA百科ScriptBoot.sh start 20 start 2 3 4 5 .) but can't seem to do the same with shutdown. I've tried (sudo update-rc.d myScriptShutdown.sh 20 start 0 6 .) with no luck. Anybody have any ideas on how I could possibly get this script to run?
If you shutdown your computer from console you can use alias:
alias shutdown='sudo myScriptShutdown.sh && sudo /sbin/shutdown'
or replace shutdown command with your command:
mv /sbin/shutdown /sbin/shutdown_original
echo "#!/bin/sh \n myScriptShutdown.sh \n /sbin/shutdown_original" > /sbin/shutdown
You can create a file ~/.bash_logout
(see /etc/skel/.bash_logout
for an example)
精彩评论