Operating System - HP-UX
1767188 Members
6117 Online
108959 Solutions
New Discussion юеВ

Re: Writing a scritp to reboot a remote machine

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

Re: Writing a scritp to reboot a remote machine

Hi Ninad,

Actually, I am doing a test case which requires remote machine to be rebooted repeated.

I need to do this n number of times with n number of machines. Hence, I wrote a script. Now, I am able to reboot machines repeatedly.

I can stop this continuos reboot mannually, but want a method through which i can stop this process from remote machine.

I have written a script for this stop perpose also, which establishes a ssh connection and removes this Sreboot file from that directory, but is not working ssh connection is timed out everytime.

I am not sure whether sshd is started before the scripts in /etc/rc.config.d/ are ran.

Can you pl. help me in this case?

Thanks for your replay.
Prasad
Bernd Reize
Trusted Contributor

Re: Writing a scritp to reboot a remote machine

Hi Prasad,

you should be able to achive this by placing a file on your controlstation/server for each remote server you want to boot, like i.e. /var/bootflags/reboot.
Then in the script copied to each server check for the existance of this remote file and reboot only if it is there.
This way you can interrupt the instant-reboot by deleting/renaming the file on your local machine.
To be sure you have ssh available on the remote server you should place the remote script into /sbin/init.d and have it called via an appropriate link in /sbin/rc2.d after sshd started up.

regards,
Bernd
Ninad_1
Honored Contributor
Solution

Re: Writing a scritp to reboot a remote machine

Prasad,

I think the way forward for you is as below
Assuming you want your remote servers to boot upto init level 3 and then reboot and continue this untill you want it to reboot.

On Local server
1. Write a script which will issue a reboot command to the remote server
2. You must have a file for each remote server in you local server. The file will have either CONTINUE or STOP word in it.
Whenever you want to start rebooting a particular remote server - open the corresponding file on your local server and write the word CONTINUE, run the script mentioned in step 1 to give the reboot command to that particular remote server.
Whenever you want the remote server to stop edit this file and write the word STOP

On remote server
1. Create a script in /sbin/init.d with name say srvreboot - Check other scripts in this location to understand the general format of the script - something like this:
case "$i" in
'start') commands to execute
;;
'stop') echo ""
;;
esac

commands to execute - Here call a script which will reside on the remote server. This script checks the contents of the file meant for this remote server in your local server through ssh and if contents are CONTINUE then issues command reboot; if contents are STOP then just echo "" .
2. In /sbin/rc3.d create a link to the above created file
cd /sbin/rc3.d
ln -s /sbin/init.d/srvreboot S99srvreboot

By mentioning S99 - will ensure that the remote server has booted and started all the services and your srvreboot script is executed almost as the remote server has booted to run level 3.

Thus by doing so you wont face the problem of ssh timeout. You can instruct the remote server when to start rebooting and each remote server will check the respective file on your local server to check if it is supposed to stop rebooting.

This is just the logic. I am sure you will be able to develop the scripts yourself. If still you face any problem. Or the above does not satisfy your requirement, let know.

Best of luck.

Ninad
Prasad Joshi
Regular Advisor

Re: Writing a scritp to reboot a remote machine

Thanks a lot to all