Results 1 to 6 of 6
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 ?
...
- 12-01-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 3
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
- 12-01-2008 #2
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!
- 12-01-2008 #3
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.
- 12-01-2008 #4Just 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.
- 12-02-2008 #5Content 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.
- 12-03-2008 #6Just Joined!
- Join Date
- Dec 2008
- Posts
- 3
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


Reply With Quote

