免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 822 | 回复: 0
打印 上一主题 下一主题

test [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-10 22:33 |只看该作者 |倒序浏览

#!/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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP