Welcome
Welcome to <strong>The Linux And Unix Menagerie</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Automate execute command - reboot - execute command

Any unix or linux shell scripting questions and answers

Automate execute command - reboot - execute command

Postby ganeshp@moris.org on Mon Dec 01, 2008 2:35 am

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
User
 
Posts: 1
Joined: Mon Dec 01, 2008 2:29 am

Re: Automate execute command - reboot - execute command

Postby laum on Mon Dec 15, 2008 3:57 pm

Hey Ganesh,

This is Mike (sometimes mod of this board -- haven't been around for a while)

You can do what you're looking to do pretty simply, depending on the level of access you have to your system (I'm assuming root or the equivalent so you can reboot.

For parts 1 and 2, create a shell script that calls reboot at the end, like:

Code: Select all
#!/bin/bash

command1

reboot


then (before you run that script) to handle parts 3 and 4, create a run_once init script. An easy way to do this is to put a an executable script in /etc/rc2.d (or substitute 2 with whatever runlevel you want the script to kick off at), like this:

Code: Select all
#!/bin/bash

command2

rm $0

reboot


Then just execute script 1 and all 4 parts should happen :) If you want to keep the init script, just remove the "rm $0 line" and, if you only want to run it the one time, use something like "file=$0;mv $file ${file}.bak.

Best wishes,

This board has been dry for so long I stopped coming by. I'll keep an eye out for your response if you still need help.

Best wishes,

Mike
ganeshp@moris.org wrote: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
laum
Site Admin
 
Posts: 46
Joined: Sun Oct 14, 2007 7:04 pm


Return to Shell Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron