nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Automate command execution - reboot-command execution

This is a discussion on Automate command execution - reboot-command execution within the Shell scripting forums, part of the Development/Scripting category; Hi All, Is there a way to execute some command and then after the command completes automatically reboot the system ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2008, 02:05 PM
Junior Member
User
 
Join Date: Dec 2008
OS: SLES
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ganeshp@moris.org is on a distinguished road
Default Automate command execution - reboot-command execution

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
Reply With Quote
  #2 (permalink)  
Old 12-01-2008, 11:42 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,668
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Write a shell script
Code:
command-1 && /sbin/reboot
If command-1 successful, then only /sbin/reboot will get called.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 12:18 PM
Junior Member
User
 
Join Date: Dec 2008
OS: SLES
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
ganeshp@moris.org is on a distinguished road
Default

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
Pause script execution untill each line is complete cosminnci Shell scripting 4 11-12-2008 07:49 PM
script to automate download and rename wademac Shell scripting 0 04-15-2008 12:51 AM
command run after reboot kasimani Shell scripting 1 03-22-2007 01:45 AM
speeding up execution kavi Linux software 6 10-16-2005 05:31 PM
How to Automate System Updates? lynx noob Linux software 1 06-24-2005 12:14 AM


All times are GMT +5.5. The time now is 04:58 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38