![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Absolute Beginner Talk The perfect starting place to find out more about computers, Linux and Ubuntu. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
First Cup of Ubuntu
![]() Join Date: Jul 2005
Beans: 7
|
i would like to run a script that does some logging of data automatically whenever i shutdown or reboot my system.
The script is already made and works fine however i am at a loss as to how to have it automatically run right before the shutdown and reboot commands are run. I initially thought of adding the following aliases to my /root/.bashrc file: Code:
alias shutdown='echo running script...; /home/user/scripts/script.py; echo Done; shutdown' alias reboot='echo Running script...; /home/user/scripts/script.py; echo Done; reboot' Also i have no idea what happens when the system is shutdown from the Gnome Panel's System menu. And that is fairly important to me sincie i often use both the shutdown option from the menu as well as the command line method. Am i not setting my aliases correctly? Is there some universal system-wide shutdown / reboot script that lists tasks to do on those events? |
|
|
|
|
|
#2 |
|
Way Too Much Ubuntu
![]() Join Date: Oct 2004
Location: Frankfurt am Main/Germany
Beans: 258
|
Re: Running a script before shutdown or reboot
I think you have to become familiar with the runlevels.
This seems to be a nice intro. (a bit old, though. So some locations/commands might have changed... ) In short you should put your script into /etc/init.d (as root) and then set up the right links in /etc/rcX.d where you want them executed when the runlevel changes. The shutdown-runlevel is 0, but maybe you also want to do your logging for a change from runlevel 2 (Debian/Ubuntu default for normal operation) to 1 (single user)? Thats up to you. Just create the links. |
|
|
|
|
|
#3 | |
|
May the Ubuntu Be With You!
![]() Join Date: Oct 2004
Location: Pennsylvania
Beans: 1,697
|
Re: Running a script before shutdown or reboot
Quote:
Code:
$ hello () { echo Hello'!'; }
$ alias hi="echo Hi."
$ hello
Hello!
$ hi
Hi.
$ type hello
hello is a function
hello ()
{
echo Hello'!'
}
$ type hi
hi is aliased to `echo Hi.'
|
|
|
|
|
|
|
#4 |
|
First Cup of Ubuntu
![]() Join Date: Jul 2005
Beans: 7
|
Thanks for the help guys. I think I've got it working now.
For completeness sake I'll post what i did, for anyone else who wants to do something similiar: From the link Juergen provided I learned to put my script: scriptname.blah in the /etc/init.d directory and create a link to the script named K02scriptname.blah in both the /etc/rc0.d/ and /etc/rc6.d/ directories. Runlevel 0 is halt. Runlevel 1 is single-user. Runlevels 2-5 are multi-user. Runlevel 6 is reboot. There are /etc/rc#.d/ folders for each # of the Runlevels. Normally during typical ubuntu use the computer is at Runlevel 2, at least thats the default setting in my /etc/inittab file. Runlevel 0 shuts the computer down and runlevel 6 reboots. /etc/rc0.d/ and /etc/rc6.d/ contain links to the scripts to be executed when switching to those runlevels. The names of the links in these folders begin with either a K or S followed by some 2-digit number and then the name of the script in /etc/init.d/ they are linked to. The K stands for kill and indicates that init will send the stop argument to the script linked to, S is for start and init sends the start argument to the script if the link begins with S. The K links are run first in the order of the 2-digit numbers that follw the K followed by the S scripts in the same way. Following the digits is the exact name of the script in the /etc/init.d/ directory. So since i wanted my script run at shutdown and reboot I named the links in the /etc/rc0.d/ and rc6.d/ directories as a kill script with a low number even though my script doesnt kill any processes and doesnt use the 'stop' argument given to it. I wanted my script to run before all of the services my script utilizes are stopped for shutdown. So now it runs right after gnome is killed and before all the other vital processes are stopped everytime my system shuts down. I hope this makes sense and definitely check Juergen's link for the real story. |
|
|
|
|
|
#5 |
|
First Cup of Ubuntu
![]() Join Date: Apr 2006
Beans: 4
|
Re: Running a script before shutdown or reboot
My question is related to this only...
This is an example when one wants to run the script after gnome has exited, what do we do if we want to run the script before Gnome exits but after we have either killed the window manager of shut it down using the Shutdown/Logoff dialog.
__________________
Visit my site at http://rohit.aroways.com/web/ |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|