Boot/Shutdown script automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Boot/Shutdown script automation
# 1  
Old 05-09-2013
Boot/Shutdown script automation

Looking to automate some commands to run at boot and poweroff in a startup/shutdown script.
How do I place it on the system so that it will be run automatically?

I don't want to use cron, not quite specific enough, random times when I may boot or shutdown.

---------- Post updated at 10:47 PM ---------- Previous update was at 10:07 PM ----------

Solved, halfway, someone who posted a solution and then took it down (??).
Can run stuff on startup, just looking for the shutdown equivalent.

*man 5 crontab*


Code:
---------
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
---------

***************
# 2  
Old 05-09-2013
I posted, then removed that, but only because I misread your post (about not wanting to use cron).

Which OS are you using?
# 3  
Old 05-09-2013
Ah right, I did wonder lol.
Yeah I didn't realise cron had that option, so that's good for the startup section that I need, just need to get an equivalent for shutdown.

Ubuntu 10.4 32-bit

---------- Post updated at 11:22 PM ---------- Previous update was at 10:55 PM ----------

Think this may be the way forward...

Customizing the Linux bootup and shutdown processes | TechRepublic
# 4  
Old 05-09-2013
Yes. That article explains it well.

You can still use the cron @reboot option to start the script on reboot if the script stops itself when terminated (i.e. when the system shuts down).

i.e. with no bells or whistles a very simple "daemon"
Code:
# /my/script
LOG=/some/logfile

trap 'echo Terminated >> $LOG; exit #do some shutdown stuff here' 0

{
  while :; do
    # do something here
    sleep 60
  done
} 2>&1 >> $LOG

Code:
crontab -l
@reboot /my/script

# 5  
Old 05-09-2013
Can I make a bash script and stick it in one of the rc* directories?
Which is best to put it in, higher or lower (0/5)?
This is what I was thinking:

/etc/rc0.d/S99myscript

So that it runs after the system has set itself up so my alterations aren't corrected as soon as they are made.
# 6  
Old 05-09-2013
Normally you would be using runlevel 3.

Code:
runlevel
who -r

That would be the place to put it. Runlevel 0 is entered when halting the system.

The script would typically go into /etc/init.d, and have a link in /etc/rc.d/rc0.d and /etc/rc.d/rc3.d as Knn and Snn for Kill and Start, where nn is a number that determines the sequence during startup / shutdown the script is run.

Code:
ln -s /etc/init.d/myScript /etc/rc.d/rc3.d/S99myscript
ln -s /etc/init.d/myScript /etc/rc.d/rc0.d/K99myscript


Last edited by Scott; 05-09-2013 at 08:10 PM.. Reason: Too many n's!
# 7  
Old 05-09-2013
I get the S/K part, but from what I see the 'nnnn' (x4) that you specified is different to my system and the article which has only 'nn' (x2).

That just your OS?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation Script for Oracle

Hi, As a Oracle Developer, I am writing many Procedures,Functions and Packages. Facing Many optimization issue after writing these Database objects. Trying to tune it manually. Can we write any Shell/Perl/Python script to Optimize these Database objects instead of doing manual check and... (1 Reply)
Discussion started by: vasuvv
1 Replies

2. Shell Programming and Scripting

Automation script

Hello All , I came across a tricky solution to devolop . Here is a part of the requirement automation . I have different set of server say : Web ( has 4 servers under it ) , App ( has 4 servers under it ) , DB ( has 2 servers under it ) Above each i have different load balancers , Say : Web... (4 Replies)
Discussion started by: radha254
4 Replies

3. Shell Programming and Scripting

awk script automation

I have the below code which calculates the time difference between src and dst from a large trace file. The code works for a given source and destination. However, I want to automate the code to go over any src and destination. The format of the source is like that: X.Y where x is always =2 and Y... (10 Replies)
Discussion started by: ENG_MOHD
10 Replies

4. Red Hat

Boot/Shutdown scripts

Server: Redhat 6.2 Goal: Startup script/Shutdown Script Overview: I'm just doing a very basic test. I'm not getting chkconfig involved. Research so far: I've found a few different ways of getting this to work, some say I can just drop the scripts in the corresponding rc directory. Others... (4 Replies)
Discussion started by: HayekSplosives1
4 Replies

5. Shell Programming and Scripting

Script Automation

Hi Gurus, I have a clearcase script that i use to check in a single file at time on my clearcase server. the script is as follows setmyview settask 75098_MSI_TRILOGY_EIM cd /vobs/Trilogy_R12/custom/msieim/12.0.0/sql/ cleartool co -nc . ct mkelem -nc Filename_1.sql cp... (3 Replies)
Discussion started by: r_t_1601
3 Replies

6. UNIX for Advanced & Expert Users

Solaris shutdown and boot history

Hello. I'm trying to get a Solaris (SunOS 5.10) shutdown and boot history. Unfortunately the /var/adm/wtmpx file does not cover the period I want to trace. It's been reset. Therefore the command, "last" (or "last reboot") does not reach back far enough. Additionally the /var/adm/messages*... (4 Replies)
Discussion started by: etlpkby
4 Replies

7. Shell Programming and Scripting

Help with Truststore automation shell script

Please close this thread. I have raise this question in appropriate thread. Thanks (0 Replies)
Discussion started by: KuldeepSinghTCS
0 Replies

8. UNIX for Dummies Questions & Answers

Script to force Oracle database shutdown when shutdown immediate does not work

I have Oracle 9i R2 on AIX 5.2. My Database is running in shared server mode (MTS). Sometimes when I shutdown the database it shutsdown cleanly in 4-5 mints and sometimes it takes good 15-20 minutes and then I get some ora-600 errors and only way to shutdown is by opening another session and... (7 Replies)
Discussion started by: aixhp
7 Replies

9. Shell Programming and Scripting

Help with Shell Script automation

can someone look into this one please... I am struck at this point. I do not know what logic to be followed here. I can go ahead with my work only, if this step is done. Please Help. I have a process X in a shell script. Once the process X is done, it generates a log file. Process X is basically... (1 Reply)
Discussion started by: ss3944
1 Replies

10. Shell Programming and Scripting

FTP automation script

Hi, I have got a requirement like this. a parameterized function custFtp which will take 5 i/ps and will do the following tasks. p1) server name p2) username p3) password p4) path name of the server where the file resides p5) file name pattern the function will work like this. ... (1 Reply)
Discussion started by: ani_datta
1 Replies
Login or Register to Ask a Question