Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > Your Distro > SuSE Linux Help > Automate execute command, reboot and execute command

Forgot Password?
 SuSE Linux Help   For help and discussions related to SuSE Linux

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 12-01-2008   #1 (permalink)
Just Joined!
 
Join Date: Dec 2008
Posts: 2
Automate execute command, reboot and execute 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
ganeshp@moris.org is offline  


Reply With Quote
Old 12-01-2008   #2 (permalink)
Just Joined!
 
darkblue's Avatar
 
Join Date: Nov 2008
Location: London
Posts: 24
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
Hi Ganesh,
You probably mean, you want to create batch process file which runs even after reboot!
well, no operating system till now has this function of giving commands which can be followed up after reboot!
But, still give a try to 'multithread' if not sequencing tasks!
If I were you, I would probably do this
execute command -1, (estimate its time till it reaches 1) and then do
shutdown -r (estimated time)
then again you need to be present for command 2

sequencing after a reboot means a program needs to be whole (not operating system dependant) which I believe is virtually difficult!!! Perhaps, in future we may have some but I don't think so because logically that program needs to handle operating system while running in it and also with it.

anyways, all I will say is, keep researching and tweaking, so far, it does not fit in logic!
darkblue is offline   Reply With Quote
Old 12-01-2008   #3 (permalink)
Trusted Penguin
 
gogalthorp's Avatar
 
Join Date: Oct 2006
Location: West (by God) Virginia
Posts: 2,647
The first process could insert a line in a startup script to run the second the second would then remove those line(s). Note that the process (ie the user starting 1) would need RW access permissions to the scripts in question. Also which level of startup scripts to use is a question that you need to address dependent on exactly what your trying to do.
gogalthorp is offline   Reply With Quote
Old 12-01-2008   #4 (permalink)
Just Joined!
 
Join Date: Nov 2005
Location: Evansville, IN
Posts: 1
Take a look a a few files /etc/init.d/after.local, boot.local, and halt.local.

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

You should be able to get creative with these files, a couple of shell scripts and maybe a control file.

If you don't have them create them and test them.
dpowers@agfinance.com is offline   Reply With Quote
Old 12-02-2008   #5 (permalink)
Content Team
 
Join Date: Dec 2008
Location: Evansville, IN
Posts: 15
You can use the /etc/init.d/*.local files to control your process. Let's say that we have three task that need to be completed and each one requires a reboot. So, our trick is to pass information into the future and still control the automation.

For the example, let's use the file /etc/init.d/after.local

If you don't have the file create one. In the file you can have it call a script such as, todolist.sh
todolist.sh will control the processing of the three tasks that are needing to be completed.

Let's also create a control file /etc/todolist.conf. This is how we will pass information into the future and control the three task. The control file only needs one entry such as, S1 or 1 for step 1.

1. With our files in place, we reboot the system and after.local file is ran which executes our todolist.sh.
2. todolist.sh check for the file /etc/todolist.conf. If found reads it and if not exits.
3. todolist.sh reads S1 from the file and processes step 1.
4. once todolist.sh receives a successful completion of step 1, it rewrites the /etc/todolist.conf file with S2, the next step, and then reboots.
5. The process is repeated for task 2 and it rewrites /etc/todolist.conf file with S3
5. The final task would delete the /etc/todolist.conf which will prevent the process from running in the future.

This is one way to handle the problem. One little caveat, the todolist.sh may need to check which runlevel it is in before executing the various steps. You can read through the file /etc/init.d/rc. Also, check the man pages for init.d for more information on the boot.local and halt.local files

enjoy and hope this helps.
Ziklag is offline   Reply With Quote
Old 12-03-2008   #6 (permalink)
Just Joined!
 
Join Date: Dec 2008
Posts: 2
Hi All,

Thank you all very much for your kind support.

dpowers and ziklag thank you very much for the information.

The Linux distribution i am using is SLES 10 SP1.
I would like to list how i achieved my requirement.

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
ganeshp@moris.org is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



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






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2