Execute a command , reboot and then execute another command
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
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. :)
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.
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.
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.
if [ $current_choice -eq 1 ]
#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
elif [ $current_choice -eq 2 ]
#Step-1 Execute my command-2, write the command to execute below
#Step-2 Reboot and run
|All times are GMT -5. The time now is 10:44 AM.|