- 论坛徽章:
- 0
|
#!/bin/sh
2 #
3 # SCRIPT: rebootalllab.sh
4 # AUTHOR: Eric
5 # DATE: 2009-04-27
6 # REV: REV_OF_CURRENT_SCRIPT
7 # PLATFORM: Linux,
8 # PURPOSE: This script is used for reboot lab machines after NFS maintenance.
9 # CHANGELOGS: description of changeLogs
10 # LOCATION: main script: /root/bin/scritp.sh, log: /root/log/script.log, temporary: /root/temporary/script.temp
11 #######################################################################
12 ################## DEFINE ALL VARIABLES HERE ##########################
13 #######################################################################
14 #
15 #
16 mailadd=a@b.com
17 #######################################################################
18 ##################### DEFINE ALL FUNCTION HERE ########################
19 #######################################################################
20 #
21 # The function to configure .......
22 rbhost(){
23 echo "==========================================="
24 echo "Machines in hostlist will reboot!Attention!"
25 echo "==========================================="
26 echo "====================Lab Machines Are Rebooting Log================"> reboot.log
27 for host in `cat hostlist`
28 do
29 /bin/ping -c 3 $host > ping.err
30 if(grep "icmp" ping.err)
31 then /usr/bin/rsh $host ls 2> reboot.err
32 if [ ! -s reboot.err ];
33 then
34 /usr/bin/rsh $host reboot
35 echo "----------------------------------------------------------------------------------------------------" >> reboot.log
36 echo "$host is rebooting." >> reboot.log
37 else
38 echo "----------------------------------------------------------------------------------------------------" >> reboot.log
39 echo "$host can't reboot! rsh can't work!" >> reboot.log
40 #cat reboot.err >> reboot.log
41 fi
42 else
43 echo "----------------------------------------------------------------------------------------------------" >> reboot.log
44 echo "$host can't reboot! Please check the hostname or if alive!" >> reboot.log
45 fi
46 done
47 echo "Action finish, You can find the detail from reboot.log file!"
48 /bin/mail $mailadd -s "Lab Machines Are Rebooting" result.log
59 for host in `cat hostlist`
60 do
61 /bin/ping -c 3 $host > ping.err
62 if(grep "icmp" ping.err)
63 then /usr/bin/rsh $host ls 2> result.err
64 if [ ! -s result.err ];
65 then /usr/bin/rsh $host uptime > a.tmp
66
67 if(grep "min" a.tmp)
68 then
69 echo "----------------------------------------------------------------------------------------------------" >> result.log
70 echo "$host 's reboot success!" >> result.log
71 else
72 echo "----------------------------------------------------------------------------------------------------" >> result.log
73 echo "$host haven't rebooted, $host is still running!" >> result.log
74 fi
75
76 else
77 echo "----------------------------------------------------------------------------------------------------" >> result.log
78 echo "$host 's reboot faild! rsh can't work!" >> result.log
79 fi
80
81 else
82 echo "----------------------------------------------------------------------------------------------------" >> result.log
83 echo "$host haven't boot up or unkonw hostname !" >> result.log
84 fi
85
86 done
87 echo "check result action done, please check result.log!"
88 /bin/mail $mailadd -s "Lab Machines Reboot Result" hostlist
120 rbhost
121 echo "Please wait 10 minutes, the result log will send to your mailbox!"
122 sleep 600
123 chhost
124 ;;
125 --all)
126 rbhost
127 echo "Please wait 10 minutes, the result log will send to your mailbox!"
128 sleep 600
129 chhost
130 ;;
131 *)
132 usage
133 ;;
134 esac
135
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/77028/showart_1961349.html |
|