Execute a command at shutdown
To dismount TrueCrypt volumes at shutdown and reboot time, I created a script, put it in
/etc/init.d/
and symlinked it into the needed /etc/rc?.d/
directories using update-rc.d
.Here is the detail:
/etc/init.d/truecrypt: #!/bin/bash case "$1" in start) #do nothing; I will mount the volume I need when I need it ;; stop) #dismount all volumes truecrypt -d ;; *) echo $"Usage: $0 -d" exit 1 esac exit $?Then I launched this command:
update-rc.d truecrypt stop 25 0 1 6 .that created these symbolic links:
/etc/rc0.d/K25truecrypt -> ../init.d/truecrypt /etc/rc1.d/K25truecrypt -> ../init.d/truecrypt /etc/rc6.d/K25truecrypt -> ../init.d/truecryptIt means that at runlevel 0, 1 and 6 (halt, single-user and reboot)
/etc/init.d/truecrypt stop
will be executed after all the scripts with the name starting in K
, for kill
, and coming before it in alphabetical order.If I wanted to run a script at start too I would symlink the script like this:
update-rc.d myscript start 25 2 3 4 5 . stop 25 0 1 6 .It means that at runlevel 2, 3, 4 and 5 (multiuser runlevels)
/etc/init.d/myscript start
would be executed after all the scripts with the name starting in S
, for start
, in alphabetical order, and at runlevel 0, 1 and 6 /etc/init.d/myscript stop
will be executed.man init
or debian.org for more info about runlevel.


Posted by: Z24 | Wed, May 04 2011 |
Category: /linux |
Permanent link |
home
Tagged as: command-line, linux, programming, script, shell