LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-01-2008, 02:21 AM   #1
ganeshp@moris.org
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Rep: Reputation: 0
Execute a command , reboot and then execute another command


Hi All,

Is there a way to execute some command and then after the command completes automatically reboot the system and then after the system reboots execute another command ?

For example look at the sequence shown below
(1) Execute command-1
(2) After the command-1 in (1) is completed,reboot the system
(3) Execute command-2
(4) After execution of command-2 reboot the sytem

Is there a way i can automate this process so that i need not reboot the system manually

Thanks and Regards
Ganesh
 
Old 12-01-2008, 02:31 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

Welcome to LQ!

You could write a "self-modifying script" that you call from
rc.local (or whichever the equivalent in your distro is - you
didn't put it in your profile).

Something along the line of

do something && sed -i '1d' my_script && reboot
do something_else && sed -i '1d' my_script && reboot



You get the idea.... untested, of course, since I
have no intention of knocking my machine over the head. :)


Cheers,
Tink

Last edited by Tinkster; 12-01-2008 at 02:32 AM. Reason: remove graphical smilies
 
Old 12-01-2008, 03:16 AM   #3
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
Quote:
Originally Posted by ganeshp@moris.org View Post
Hi All,

Is there a way to execute some command and then after the command completes automatically reboot the system and then after the system reboots execute another command ?

For example look at the sequence shown below
(1) Execute command-1
(2) After the command-1 in (1) is completed,reboot the system
(3) Execute command-2
(4) After execution of command-2 reboot the sytem

Is there a way i can automate this process so that i need not reboot the system manually

Thanks and Regards
Ganesh
1. you write a script: shutdown -r now.
2. command1 here.
3. shutdown -r now
4. command2 here.

5. make it executable chmod 777 [name of file].
6. link it in rc3.d, rc4.d, rc5.d by typing

ln -s [your script] /etc/rc3.d/S97myscript
ln -s [your script] /etc/rc4.d/S97myscript
ln -s [your script] /etc/rc5.d/S97myscript

S of 97 meaning "Start" ...K is "Kill"...make sure you choose different number after Snn.

7. if you finished... delete the link by rm command.
 
Old 12-03-2008, 12:51 AM   #4
ganeshp@moris.org
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Hi All,

Thank you very much for your kind support. The Linux distribution i am using is SLES 10 SP1.
I would like to list some of the things that i found out in the course of solving this issue.

boot.local runs before the runlevels are entered
after.local runs after entering the final run level
halt.local runs on the system halt

To solve the problem in my hand i created a file called "to_do.sh" and then executed this file from file "after.local".
File "after.local" was not present in /etc/rc.d/ folder. I created this file and added the line "sh /tmp/to_do.sh" in this file.

Content of my "to_do.sh" is given below.

With this i was able to achieve my requirement.

Thank you,
Regards,
Ganesh

Content of my "to_do.sh"In this file i am reading the choice after reboot from a file called choice.txt and after the current choice is executed i am rewriting my next choice to choice.txt for the next reboot.

#!/bin/sh

current_choice=$(</tmp/choice.txt)

if [ $current_choice -eq 1 ]
then
#Step-1 Execute my command-1, write the command to execute below

#Step-2 Change the choice ,so that in next reboot the elif gets executed
echo "2">/tmp/choice.txt

#Step-3 reboot
reboot

elif [ $current_choice -eq 2 ]
then
#Step-1 Execute my command-2, write the command to execute below

#Step-2 Reboot and run
echo "3">/tmp/choice.txt

#Step-3 reboot
reboot

else
echo "Completed">/tmp/Comp.txt
fi
 
  


Reply



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
How do i execute the command? kensim00 Linux - Newbie 9 06-29-2007 03:06 PM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
How to make a command execute on it every reboot? peterguo Linux - Software 5 11-04-2004 07:23 PM
command execute without ./ kaon Slackware 11 09-15-2004 05:14 PM
Execute Command lawrencegoodman Linux - Newbie 2 10-23-2003 08:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:10 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
Open Source Consulting | Domain Registration