Solved

Linux runlevel 0 question

Posted on 2011-09-22
6
603 Views
Last Modified: 2012-05-12
Hi,
    I need to have a script run at shutdown that saves some log files from ramdisk to Compact Flash, so they will be there on next bootup.(I keep them in ramdisk so as not to abuse the CF)

I thought I could just do this by having a script in /etc/rc.d/init.d, and the having it get called when i went into runlevel 0, like so...
      K09save_logs -> ../init.d/save_logs

But when it would not work, I, (O.K. my boss), finally figured out that whatever program excutes the Kill, first checks to see if there is a process called "save_logs" running. Since there is no process, it does not bother calling the script.

Is there some simple way to override this behavior,(i.e force the runlevel change to execute the script) or must I write a little process called "save"logs",that just sits there so it can be found at shutdown time?

                            Thanks.
                            Steve
0
Comment
Question by:slats52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:sakman
ID: 36581612
Did you put K09save_logs in /etc/rc.d/rc0.d?  

If so, the scripts in rc0.d should be executed as the system is shutting down.

If not, and you put the script in /etc/rc.d/init.d, then you should create a link for that script in rc0.d
0
 

Author Comment

by:slats52
ID: 36581801
Hi sakman,
    Thanks for the quick response.

Yes, I did put the symbolic link it rc0.d. I implied that by showing showing the link in my message, but I should have spelled it out better.

What I have is;
     The sym link. --->                     /etc/rc.d/rc0.d/K09save_logs -> ../init.d/save_logs
     and the script --->                   /etc/rc.d/init.d/save_logs

But what I found, by a lot of trial and error, is that the program (presumably 'init', actually looks for a running process with the same name as your sym link (minus of course the Kxx).
  So, in other words it looks for a process named 'save_logs'. Since there is no actual running process by this name, it does NOT bother to execute the script.
I proved this by making a sym link (in rc0.d) named "K09sshd --> ../init.d/save_logs". Now, since 'init' found that 'sshd' was, in fact runnig, it gladly excuted my script.

   I hope i've made this more clear.

                  Steve


 


0
 
LVL 4

Accepted Solution

by:
sakman earned 500 total points
ID: 36581870
OK.  

Maybe you can add your routine or call your script from /etc/init.d/halt (/etc/rc.d/rc0.d/S01halt) - that script is executed during shutdown.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 4

Expert Comment

by:sakman
ID: 36581913
Or - rename your script with an "S" - so that it is run when entering run level 0.  Since halt is "S01", you might need to rename S01halt to S02halt and then name your script to S01save_logs so it runs first.  

Just be careful when fooling around with basic system startup/shutdown scripts.
0
 

Author Closing Comment

by:slats52
ID: 36582004
GREAT ideas sakman!

   I was already in the midst of trying your first idea when the second one came through.

 It worked like a charm.

 I have no doubt the second idea will work also.

 

                       Many thanks for your ideas...
                       Steve

P.S. You saved me an afternoon of writing a stupid process to just sit there and do nothing. (the way I was going to tackle the problem).
     Sometimes you just don't see the forest through the trees...
0
 
LVL 4

Expert Comment

by:sakman
ID: 36582023
Cool.  Glad I could help.  Yeah I know all about forest and trees - sometimes I don't even see that the forest is on fire!

BTW, if you decide to rename the S01halt script - remember it's a link.  So probably delete it and then relink /etc/init.d/halt to S02halt.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question