Author Topic: How do I run a command on shutdown/logout?  (Read 283 times)

Offline Phil

  • Hero Member
  • *****
  • Posts: 740
How do I run a command on shutdown/logout?
« on: August 10, 2012, 06:15:40 AM »
I am puzzling over this. If I want to run a command on say either shutdown or perhaps on user logout where would it go?

I presume a script is run somewhere and I presume I can add the command I want to run there.

Offline Xenaflux

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3834
Re: How do I run a command on shutdown/logout?
« Reply #1 on: August 10, 2012, 06:46:20 AM »
Click <PC> icon in left-bottom
Just one up is < command>
pressing that brings up a small box ( on top with me )
Type in ..shutdown.....the system will shutdown
Type in ..logout...........the system will logout/login
Type in ..Reboot.......>>>>>>WINE will start  ??     :o      ::)
this is the new minime
The great thing in this world is not so much where we stand,
as in what direction we are moving.
                                                    (Oliver Wendell Holmes )

Offline Phil

  • Hero Member
  • *****
  • Posts: 740
Re: How do I run a command on shutdown/logout?
« Reply #2 on: August 10, 2012, 07:10:11 AM »
Hi Xenaflux,

I am thinking in terms of unmounting all truecrypt volumes automatically on shutdown, >truecrypt -d. If you do not do this then on next bootup the volumes are mounted and in place, bad idea. Need to have that command somewhere in the shutdown sequence for when I forget.

I have been looking for the shutdown script (running kde). Nothing obvious, probably overlooking something easy.

Offline Xenaflux

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3834
Re: How do I run a command on shutdown/logout?
« Reply #3 on: August 10, 2012, 07:44:36 AM »
Phil

I can not help you with that, but.....if I see or hear about something like that, I let you know.

Xena

anything of use here:
http://www.oreillynet.com/linux/cmd/
« Last Edit: August 10, 2012, 07:46:21 AM by Xenaflux »
The great thing in this world is not so much where we stand,
as in what direction we are moving.
                                                    (Oliver Wendell Holmes )

Offline Phil

  • Hero Member
  • *****
  • Posts: 740
Re: How do I run a command on shutdown/logout?
« Reply #4 on: August 10, 2012, 02:13:09 PM »
I have been digging.

I think I put an executable script in rc5 prefixed with say K99script, so on logout of the gui it executes
(or maybe in rc0 turn off computer)

Not tried it yet.....

###############

There are 7 folders (which are typically found in the /etc directory, if
they are not there search the /etc directory because they may be i another
subdirectory of /etc):
- rc0.d
- rc1.d
- rc2.d
- rc3.d
- rc4.d
- rc5.d
- rc6.d

These correspond to the different run levels that Linux has.
- Runlevel 0 is when you turn your computer off.
- Runlevel 1 is single user mode
- Runlevel 2 is multi user mode w/o NFS
- Runlevel 3 is multi user mode w/NFS
- Runlevel 4 is reserved for different vendors to define
- Runlevel 5 is GUI mode.
- Runlevel 6 is when you reboot your computer.

If you look into the rc0.d you'll see a bunch of scripts (or symlinks to
scripts). They either start with a "K" or an "S". When your Linux system
starts into a Runlevel it looks inside of it's corresponding rcX.d folder.
Scripts that start with a "K" are stopped or killed. Scripts that start with
an "S" are started. You'll also notice that after the "S" or the "K" is a
number. When scripts are started it will start "S1script" before
"S99script". The reverse goes for "K1script" and "K99script" (this is killed
first)

#####################