LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-07-2012, 01:04 PM   #1
icmp_request
Member
 
Registered: Jun 2007
Location: São Paulo - Brazil
Distribution: Linux Mint
Posts: 54

Rep: Reputation: 15
Adding a shutdown/reboot script?


Hello!

I'm using Debian, and I would like to know better, if possible, how the scripts work. I have a minimal system installed.

Let's say I wish to run a script on reboot (runlevel 6) that just creates a file named "worked" under /boot

I've tried many ways to do that, but the script just doesn't run?

Here's the source of /etc/init.d/test
Code:
#!/bin/sh

start () {
touch /boot/worked
}

stop () {
touch /boot/worked
}


case "$1" in
  start)
     start || exit 1
     ;;
  stop)
     stop || exit 1
     ;;
  force-reload|restart)
     stop && sleep 3
     start || exit 1
     ;;
  *)
     echo "Usage: start, stop, reload"
     exit 1
esac

exit 0
And here's my ls -l /etc/rc6.d :

Code:
total 4
lrwxrwxrwx 1 root root  13 Apr  7 11:55 K01atd -> ../init.d/atd
lrwxrwxrwx 1 root root  15 Apr  7 11:56 K01exim4 -> ../init.d/exim4
lrwxrwxrwx 1 root root  13 Apr  7 12:19 K01gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root  17 Apr  7 11:47 K01urandom -> ../init.d/urandom
lrwxrwxrwx 1 root root  18 Apr  7 11:55 K02sendsigs -> ../init.d/sendsigs
lrwxrwxrwx 1 root root  17 Apr  7 11:55 K03rsyslog -> ../init.d/rsyslog
lrwxrwxrwx 1 root root  22 Apr  7 11:55 K04umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx 1 root root  20 Apr  7 11:56 K05nfs-common -> ../init.d/nfs-common
lrwxrwxrwx 1 root root  17 Apr  7 11:56 K05portmap -> ../init.d/portmap
lrwxrwxrwx 1 root root  20 Apr  7 11:56 K06hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx 1 root root  20 Apr  7 11:56 K06networking -> ../init.d/networking
lrwxrwxrwx 1 root root  18 Apr  7 11:56 K07ifupdown -> ../init.d/ifupdown
lrwxrwxrwx 1 root root  18 Apr  7 11:56 K08umountfs -> ../init.d/umountfs
lrwxrwxrwx 1 root root  20 Apr  7 11:56 K09umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root  16 Apr  7 11:56 K10reboot -> ../init.d/reboot
-rw-r--r-- 1 root root 351 Jan  1  2011 README
lrwxrwxrwx 1 root root  14 Apr  7 13:22 S00test -> ../init.d/test
Permissions of /etc/init.d/test:

Code:
-rwxr-xr-x 1 root root 308 Apr  7 13:15 /etc/init.d/test
It's my understanding that although all the scripts on runlevel 6 begin with "K", init would run the scripts beginning with "S" first. Anyways, I've already tried to rename it to "K00test" and didn't work.

/boot is in the same partition. It's just an example I could have made it create the file on /, /home, etc. doesn't matter.

I must be missing something very "basic"...

Thanks in advance for any help!
 
Old 04-08-2012, 09:45 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,735
Blog Entries: 27

Rep: Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060
Member response

Hi,

Why??

Safest would be to use '/sbin/shutdown';
Quote:
excerpt from 'man shutdown';
NAME
shutdown - bring the system down

SYNOPSIS
/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]

DESCRIPTION
shutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is
blocked. It is possible to shut the system down immediately or after a specified delay. All processes are first notified that the sys-
tem is going down by the signal SIGTERM. This gives programs like vi(1) the time to save the file being edited, mail and news process-
ing programs a chance to exit cleanly, etc. shutdown does its job by signalling the init process, asking it to change the runlevel.
Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a state
where administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shutdown. To see which
actions are taken on halt or reboot see the appropriate entries for these runlevels in the file /etc/inittab.

OPTIONS
-a Use /etc/shutdown.allow.

-t sec Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, before changing to another runlevel.

-k Don't really shutdown; only send the warning messages to everybody.

-r Reboot after shutdown.

-h Halt or poweroff after shutdown.

-H Halt action is to halt or drop into boot monitor on systems that support it.

-P Halt action is to turn off the power.

-n [DEPRECATED] Don't call init(8) to do the shutdown but do it ourself. The use of this option is discouraged, and its results are
not always what you'd expect.

-f Skip fsck on reboot.
 
Old 04-08-2012, 06:00 PM   #3
icmp_request
Member
 
Registered: Jun 2007
Location: São Paulo - Brazil
Distribution: Linux Mint
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by onebuck View Post
Hi,

Why??

Safest would be to use '/sbin/shutdown';
Sorry, I think I've misguided my point on the topic title. I meant adding a script ON shutdown/reboot. Very sorry about that, I'll edit the topic title.

Edit: Can't change the thread topic title... =/
 
Old 04-08-2012, 09:17 PM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 837

Rep: Reputation: 201Reputation: 201Reputation: 201
Try putting it first. (Off hand it seems that your script is never reached since some earlier script is actually rebooting the system).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Init.d script not executing at shutdown and reboot roberbizimhatemo Linux - General 13 05-04-2012 07:28 AM
Shutdown and Reboot Linux System via php script ramasubbu1984 Linux - Newbie 7 03-24-2009 09:09 AM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 01:34 PM
Need help adding a script to shutdown sequence trapix22 Linux - Newbie 1 12-29-2007 01:08 AM
Adding reboot & shutdown to gnome logoff ringwraith Slackware 7 12-13-2003 11:27 AM


All times are GMT -5. The time now is 12:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration