The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shutdown Script not executing... eliraza6 Linux 0 02-19-2008 07:56 AM
Shutdown script kingsto88 HP-UX 0 03-20-2007 08:43 PM
A script for shutdown kelu UNIX for Dummies Questions & Answers 12 08-23-2006 10:09 PM
remote shutdown script soliberus Shell Programming and Scripting 2 01-31-2005 06:46 PM
logout/shutdown script ropers UNIX for Dummies Questions & Answers 1 08-02-2002 03:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2005
alpha_manic alpha_manic is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 5
Shutdown script

Hi Guys,

I want to execute few of my bash script, so that whenever someone calls shutdown now -r command, I want my script to execute first before shutting down.

Any help please?????

I've just started playing with the unix system, so far its been brilliant....
  #2 (permalink)  
Old 09-14-2005
indo1144's Avatar
indo1144 indo1144 is offline
Registered User
  
 

Join Date: Jun 2002
Location: Netherlands
Posts: 54
When you reboot, what you actually do is change the runlevel to 6. In /etc/init.d you can find all kinds of scripts that are started/stopped when entering specific runlevels. This is where your script should live (or be symlinked to).

Now change into /etc/rc6.d. You see lots of symlinks to the scripts in /etc/init.d. Some start with a K, some start with an S. When changing to runlevel 6 (read: you execute a shutdown -r now), the services that start with a K will be stopped, the ones starting with an S will be started. (See where I'm going?)

The number after K or S is an indication of the order in which these scripts will be run.

Code:
root@k2:/etc/rc6.d# ls -l
total 0
lrwxrwxrwx  1 root root  18 Apr  4  2001 K10ipchains -> ../init.d/ipchains
lrwxrwxrwx  1 root root  14 Mar 26  2001 K11cron -> ../init.d/cron
lrwxrwxrwx  1 root root  17 Mar 26  2001 K12kerneld -> ../init.d/kerneld
lrwxrwxrwx  1 root root  16 Apr  4  2001 K20apache -> ../init.d/apache
lrwxrwxrwx  1 root root  15 Mar 26  2001 K20inetd -> ../init.d/inetd
lrwxrwxrwx  1 root root  17 Mar 26  2001 K20logoutd -> ../init.d/logoutd
lrwxrwxrwx  1 root root  17 Mar 26  2001 K20makedev -> ../init.d/makedev
lrwxrwxrwx  1 root root  17 Apr  4  2001 K20postfix -> ../init.d/postfix
lrwxrwxrwx  1 root root  16 Dec  9  2003 K20rinetd -> ../init.d/rinetd
lrwxrwxrwx  1 root root  15 May  9  2003 K20snmpd -> ../init.d/snmpd
lrwxrwxrwx  1 root root  13 Mar 29  2001 K20ssh -> ../init.d/ssh
lrwxrwxrwx  1 root root  19 Jan 26  2005 K20tivoli-sm -> ../init.d/tivoli-sm
lrwxrwxrwx  1 root tiggr 15 Apr 12  2001 K21resin -> ../init.d/resin
lrwxrwxrwx  1 root tiggr 13 Apr  9  2001 K23ntp -> ../init.d/ntp
lrwxrwxrwx  1 root root  20 Dec  6  2003 K25hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx  1 root tiggr 25 Jul 10  2002 K25nfs-user-server -> ../init.d/nfs-user-server
lrwxrwxrwx  1 root  1005 15 Oct 10  2003 K25resin -> ../init.d/resin
lrwxrwxrwx  1 root root  19 Mar 26  2001 K30setserial -> ../init.d/setserial
lrwxrwxrwx  1 root tiggr 17 May 23  2002 K50proftpd -> ../init.d/proftpd
lrwxrwxrwx  1 root tiggr 14 Apr 20  2003 K85bind -> ../init.d/bind
lrwxrwxrwx  1 root root  13 Mar 26  2001 K89atd -> ../init.d/atd
lrwxrwxrwx  1 root root  15 Apr  4  2001 K89klogd -> ../init.d/klogd
lrwxrwxrwx  1 root root  18 Mar 26  2001 K90sysklogd -> ../init.d/sysklogd
lrwxrwxrwx  1 root root  17 Mar 26  2001 S10portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root  18 Mar 26  2001 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx  1 root root  17 Mar 26  2001 S30urandom -> ../init.d/urandom
lrwxrwxrwx  1 root root  22 Mar 26  2001 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx  1 root root  20 Mar 26  2001 S35networking -> ../init.d/networking
lrwxrwxrwx  1 root root  18 Mar 26  2001 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx  1 root root  16 Mar 26  2001 S90reboot -> ../init.d/reboot

The above listing is from a Debian-server, your listing may look different.

Now, to execute a script before a reboot, just make sure it's listed here.

You should carefully pick the order in which you execute YOUR script, you don't want to stop your mailserver if you want your script to mail you something. I think you should be safe if you let the symlink to your script start with S10, so it gets executed almost at once.
  #3 (permalink)  
Old 09-14-2005
alpha_manic alpha_manic is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 5
I have a brand new installation and only consist of S20reboot. So according to your article above, if i create a script called S10test which could contain something like :

Code:
#! /bin/sh
echo "hello unix world"

Then if I give it correct premission i.e. chmod a+rwx S10test. Then can I do shutdown now -r and I should see it been executed. Is this correct??


Thanks very much. I'll be unix guru at this rate (LOL) ...
  #4 (permalink)  
Old 09-14-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Scripts starting with S are executed on Startup. Scripts starting with K are executed on shutdown. So, no, your script will be seen on boot, not on shutdown.
  #5 (permalink)  
Old 09-14-2005
vertigo23's Avatar
vertigo23 vertigo23 is offline
Registered User
  
 

Join Date: Jul 2005
Location: SF, CA
Posts: 73
Er, no.

Quote:
Originally Posted by RTM
Scripts starting with S are executed on Startup. Scripts starting with K are executed on shutdown. So, no, your script will be seen on boot, not on shutdown.
It's my understanding that K scripts are Killed when you enter that runlevel, and S scripts are Started. So rc6.d/K10ssh will kill the ssh daemon when you enter runlevel 6, but rc6.d/S10foo will start the foo daemon.

All that depends on the init.d/foo or ssh scripts using the right functions to parse $0 correctly, of course. If you don't do that, I don't think it matters what you name the rc?.d script - it'll just run when you enter that runlevel.
  #6 (permalink)  
Old 09-14-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Original request
Quote:
I want my script to execute first before shutting down.
He wants something to run before shutting down - that means he wants a K script - that is why I stated the difference between S and K - he stated he wanted to see execution BEFORE shutting down - naming the script S10test, would cause him to see execution AFTER shutdown on reboot.
  #7 (permalink)  
Old 09-14-2005
indo1144's Avatar
indo1144 indo1144 is offline
Registered User
  
 

Join Date: Jun 2002
Location: Netherlands
Posts: 54
Quote:
Originally Posted by alpha_manic
I have a brand new installation and only consist of S20reboot. So according to your article above, if i create a script called S10test which could contain something like :
Code:
#! /bin/sh
echo "hello unix world"

Then if I give it correct premission i.e. chmod a+rwx S10test. Tzen can I do shutdown now -r and I should see it been executed. Is this correct??
That's right, although the execution of your script may happen so fast, you won't see the output.
Quote:
Originally Posted by rtm
Scripts starting with S are executed on Startup. Scripts starting with K are executed on shutdown. So, no, your script will be seen on boot, not on shutdown.
This can be quite confusing. Last week I had to dig into this matter, because I had to create my own init-script from scratch and I stumbled upon the following text.
Quote:
From Internet link : The name of each symbolic link begin with either a K or an S. The K links are processes that are killed on that runlevel, while those beginning with an S are started.
So the S10test script will in fact be executed prior to the actual reboot.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0