Script to Reboot and Confirm


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Reboot and Confirm
# 1  
Old 02-16-2011
Script to Reboot and Confirm

On my Solaris box I have to reboot some devices like below.
However I think this can be done through a script. I've create a list that contains the devices IP addresses.

Here's the logic:
Reboot 4 devices and sleep for 5mins(300s.) While the devices are rebooting, I would like to confirm that it was indeed reboot from the reboot log file that logs a single line: "found IPADDR."

After I've confirmed the devices have rebooted and the 300s expired I would like to continue with the next 4 IPs on the list and not start from the top of the list again.

Current Script to Reboot Device
HTML Code:
deviceReboot -reboot <IP> 
sleep 1
deviceReboot -reboot <IP> 
sleep 1
deviceReboot -reboot <IP> 
sleep 1
deviceReboot -reboot <IP> 
sleep 1
Sleep 300
I would like to do the following
HTML Code:
deviceReboot -reboot <IPlist> 
I'm not sure how to implement the "SLEEP 1" for each device and "SLEEP 300" after the 4th device. In addition confirm from the reboot log after all 4 device have been reboot.
# 2  
Old 02-16-2011
Something like this might work:
Code:
#!/bin/ksh
i=1;
LIST="1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7 1.2.3.8 1.2.3.9 1.2.3.10"
for ip in $LIST; do
  deviceReboot -reboot $ip
  if [ $((i%4)) == "0" ]; then sleep 300
  else sleep 1
  fi
  grep "found $ip" /log/file
  if [ $? != "0" ]; then echo "$ip not restarted, exiting"; break
  fi
  ((i++))
done

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 02-16-2011
Thanks Bart! I have to try this in the night, so I'll let you know how it works!
# 4  
Old 02-16-2011
Hello, ravzter and bartus11:

Unless i misread, I don't think bartus11's script will do what you want. Except for every 4th ip address, it checks for the ip address in the log after only giving the device 1 second to reboot. I think you'd need to store the currently rebooting 4 ip addresses in a string and then loop over them after the 5 minute sleep.

The following isn't tested, not even for syntax errors, but I believe it's more in line with what you're trying to accomplish:
Code:
#!/bin/ksh

i=1;
ips_all="1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7 1.2.3.8 1.2.3.9 1.2.3.10"
ips_rebooting=
for ip in $ips_all; do
    ips_rebooting=$ips_rebooting' '$ip
    deviceReboot -reboot $ip
    if [ $((i%4)) -ne 0 ]; then
        sleep 1
        continue
    else
        sleep 300
    fi
    for ip in $ips_rebooting; do
        if ! grep "found $ip" /log/file >/dev/null; then
            echo "$ip not restarted, exiting"
            exit 1
        fi
    done
    ips_rebooting=
    ((i++))
done

That retooling of bartus11's script also exits if an ip is not found in the log. Perhaps it may be desirable to continue on; if so, remove the 'exit 1' line.

Also, you'll need to rotate or delete that log file after each run if you're always using the same ip addresses.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 5  
Old 02-17-2011
I will try this one; however, I would also like to try another option:

Not to worry about the 300s and 4 at a time. Just reboot consecutively, sleep for 3s after each, and verify against reboot log.

---------- Post updated 02-17-11 at 01:33 AM ---------- Previous update was 02-16-11 at 01:37 PM ----------

It's not rebooting the devices. I think it's because I have the ips saved to a file, and script is assigned the IPs to variable.

HTML Code:
LIST="1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7 1.2.3.8 1.2.3.9 1.2.3.10"
I have the ips saved to a file in my /tmp directory. How would be able to use the file instead of the actual IPs?
HTML Code:
LIST="/tmp/ips"
HTML Code:
ips_all="1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7 1.2.3.8 1.2.3.9 1.2.3.10"
HTML Code:
ips_all="/tmp/ips"
# 6  
Old 02-17-2011
Code:
LIST=`cat /tmp/ips`

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 02-17-2011
Thanks Bartus! This works!

---------- Post updated at 05:05 AM ---------- Previous update was at 03:33 AM ----------

Bartus can I bother for one more change: How do I modify the script to continue after it confirms the reboot from the logfile? What's happening is that if the device doesn't log it's reboot in time the script exits, which is the logic of it anyway.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simply Bash Script to Confirm that there are 2 Files in Same Folder

Im looking for 2 Files -> *.WAV and *.wav with find . -name 'unavail.wav' -o -name 'unavail.WAV' I need to list the Folders that contains these 2 Files? Thx in advance (13 Replies)
Discussion started by: valdez
13 Replies

2. Shell Programming and Scripting

Start Script on system reboot

Hi, I have the following script that looks for a certain file and then executes the start.sh file. How can i make this process to kick when the box reboots. Please advice if ; then /u01/Essbase/Oracle//Middleware/user_projects/epmsystem7/bin/start.sh; rm... (8 Replies)
Discussion started by: thinkingeye
8 Replies

3. Shell Programming and Scripting

Remote reboot script

I'm a beginner in shell scripting and doing simple scripts for work requirement. #!/bin/bash for blade in `cat machines.txt` do rsh $blade 'reboot' done but when I try it with root password it's throwing error saying permission denied.We're using same root password for all... (3 Replies)
Discussion started by: ratheeshp
3 Replies

4. AIX

Need to confirm something regarding TL upgrades

Hi everyone, My current AIX OS level is "7100-01-06-1241" and I am planning to upgrade it to " 7100-02-03 ". Can i directly upgrade it to "7100-02-03" from 7100-01-06" ? or first i need to upgrade the "7100-01-06" LPAR to TL 02 and then reboot and then upgrade it to TL 02 SP03 ? ... (4 Replies)
Discussion started by: System Admin 77
4 Replies

5. Solaris

Reboot required on Server, Just confirm my settings.

Hi Guys, I need to reboot one Server as the newly inserted disk is not getting detected in system , I have also confirmed with Sun Support and finally it was the reboot which was required after doing all troubleshooting stuff. So I have disassembled the mirror and kept working disk's single... (3 Replies)
Discussion started by: manalisharmabe
3 Replies

6. Shell Programming and Scripting

Reboot script issue

Hi guys I am troubleshooting a script that informs me when a system has rebooted. The script is placed in /etc/rc3.d folder under root. The script is as follows: . /opt/scripts/function.sh PATH=/usr/bin EMAIL_ADD=<email address> ... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

7. Shell Programming and Scripting

script to reboot multiple hosts

Hi Expert, How to create a script to reboot multiple hosts in linux? Thank you. (5 Replies)
Discussion started by: regmaster
5 Replies

8. Linux

Run a script during reboot/startup

Hi all, i have a script in /etc/init.d directory. -rwxr-xr-x 1 root root 26 Mar 28 16:00 myscript I need it to run when my linux reboots/startup. However is it not being executed. Do i need to put in in the rc.local directory? (1 Reply)
Discussion started by: new2ss
1 Replies

9. Solaris

different between soft reboot and hard reboot

Hi Guru's Can any want here could explain to me the different between soft reboot and hard reboot . Best Regards Seelan (3 Replies)
Discussion started by: seelan3
3 Replies

10. Shell Programming and Scripting

Confirm before delete.

I have a script that archive files then delete.How do Its working fine,however,before I perform the delete operation,I want to verify that indeed the FILE is in the path of folder I want to archive. For example,I have a path /A/B I want all files in B to be archived,the scripts lists all the... (5 Replies)
Discussion started by: kayarsenal
5 Replies
Login or Register to Ask a Question