Operating System - HP-UX
1777397 Members
3185 Online
109069 Solutions
New Discussion юеВ

Re: Writing a scritp to reboot a remote machine

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

Writing a scritp to reboot a remote machine

Hi all,

I am writing a script to reboot a remote machine.

In that script, I am just copying another script (name Sreboot) having statement "reboot" to /etc/rc.config.d/ directory and then rebooting the machine.

When the remote machine is restarted again it again reboots because of Sreboot script.
This goes on.

Now I want to stop this.

I am trying to remove script "Sreboot" through ssh connection. but connection gets timed out. Is there any way to remove this file from directory /etc/rc.config.d/

I want to run this test many times. So, i donot want to go in maintianence mode and mannually remove it.

I want a way to remove this file from remote machine.

Can any one help? Is there any other way to do this?

Thanks in advance.
Prasad
13 REPLIES 13
SANTOSH S. MHASKAR
Trusted Contributor

Re: Writing a scritp to reboot a remote machine

Hi Prasad,

What is the content of Script Sreboot ?

-Santosh
RAC_1
Honored Contributor

Re: Writing a scritp to reboot a remote machine

First thing is, for such things, you should nto eb using a file placed in /etc/rc.config.d/. This dir holds config files. If you want to reboot machines remotely, just have ssh/remsh set with root and reboot command in it.
There is no substitute to HARDWORK
Chan 007
Honored Contributor

Re: Writing a scritp to reboot a remote machine

Hi,

Get it to the remote system by GSP/MP, do a single user boot byt interupting the boot process. remove the file.

If you wanted to reboot a remote system, why can't you schedule it via cron.

Chan
Prasad Joshi
Regular Advisor

Re: Writing a scritp to reboot a remote machine

It contains.

#!/bin/csh
reboot &


Thanks for ur concern feedback
Chan 007
Honored Contributor

Re: Writing a scritp to reboot a remote machine

Prasad,
if reboot is what used said, then use my method to stop this. if you don't have GSP/MP, call someone in that data center or raise call with HP.

Chan
Prasad Joshi
Regular Advisor

Re: Writing a scritp to reboot a remote machine

Hi,

I do not want to mannually do it.

Consider there are 2 machines A and B

from B I am doing
# UpDown start A
this copies the script to /etc/rc.config.d/
then reboot machine A for first time
I am using ssh for this

Now machine A goes on rebooting

Now i want a way to do this
# UpDown stop A
this should remove the file from /etc/rc.config.d/

Thanks & reagards
Prasad
Antonio Cardoso_1
Trusted Contributor

Re: Writing a scritp to reboot a remote machine

Prasad,

consider using ssh to remotely run the reboot (or shutdown) command. This is the most secure.

alternaltive: perl + telnet client.
I could provide you an example of this if needed.
SANTOSH S. MHASKAR
Trusted Contributor

Re: Writing a scritp to reboot a remote machine

Hi Prasad,

U r using ssl to reboot sys B from sys A,
instead of keeping ur script in /etc/rc.config.d keep it somewhere else. Since during execution of /sbin/rc all the files in
/etc/rc.config.d r executed to set the config.
variables. If u r placing ur script with a
reboot & command in it the system keeps rebooting.
If keeping system rebooting is not ur intension
then keep this script somewhere other than
/etc/rc.config.d (say /usr/sbin) , I usually
place it there only.


To get rid of repeatative rebooting u have to
get access of ISL of remote server, for this
as suggested by Chan u have to configure
GSM/MP, It is very useful to get it configured.
Through GSM u can boot into single user and remove the script
from /etc/rc.config.d

Hope it helps u.

Regards

-Santosh
Ninad_1
Honored Contributor

Re: Writing a scritp to reboot a remote machine

Prasad,

I am unable to imagine what you are trying to achieve. If you want to reboot your remote machine just once why put script in /etc/rc.confg.d ??
Your local machine can execute a reboot command once through ssh whenever you wish to reboot the remote server.
Now the question remains is are you trying to break the reboot loop now so that you can login/use the remote server - if yes write a script on your local machine which will continuous ping the remote server and if able to reach the remote server run a ssh to replace the Sreboot script in /etc/rc.config.d in the remote server by a dummy script - this can be a blank file with the same name ie Sreboot.

while true
do
if [[ $(ping remote_server -n 2 | grep "%" | cut -f 1 -d "%" | awk '{print $NF}') = "0" ]]
then

sleep 5
fi
done

The reason I have kept the above script in loop is that even after you receive response to ping the other services for network may have not come up yet to eable you copying the file to remote server. Simultaneously you can check if the server has stopped rebooting - then you can interrupt this script on local server.
Then you can ammend what you were doing wrong.

Hope this helps,
Ninad
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