《电子电脑》显示文章详细内容: [展开] [回复] [网址] [举报] [屏蔽]
红男爵
红男爵目前处于离线状态
  查看红男爵个人资料   给红男爵发悄悄话   将红男爵加入好友   搜索红男爵所有发表过的文章   给红男爵发送电子邮件      

有UNIX 下的shell 高手吗? 帮看一下这个脚本做什么的,写的水平如何?
#!/bin/sh

TMPFILE="lastcheck.tmp"


[ -f $LOG_RUNNINGCONF ] || exit 1

usage() {
echo "Usage: $(basename $0) [IP/HostName/File] [Interval (seconds)] [Total] [Report Email]"
echo "IP -- Dest IP or HostName or File that contain IP list to monitor"
echo "Interval -- Check interval"
echo "Total -- Total check number in a row"
echo "Report's Email -- Email address to send mail to"
exit 2
}

sanity_check()
{
# check Total argument number
[ $# -ne 4 ] && usage

# Check Valid input for interval
expr $2 + 1 1>/dev/null 2>$1
if [ $? -gt 0 ]; then
echo "Please input digital for Interval"
exit 1
else
[ $2 -gt 5 ] && echo "Warning: Interval should be less than 5 seconds" && exit 2
fi

# Check Valid input for Total
expr $3 + 1 1>/dev/null 2>$1
if [ $? -gt 0 ]; then
echo "Please input digital for Total count"
exit 1
else
[ $3 -gt 10 ] && echo "Warning: Total try count should be less than 10 seconds" && exit 3
fi
}

action() {
echo "0" > $TMPFILE
while [ 1 ]
do

sanity_check $@
eval ping -c $3 -i $2 $1 1>/dev/null 2>$1
if [ $? -gt 0 ]; then #Ping Failed
#echo "Ping failed"
currentFlag=1
lastFlag=$(cat $TMPFILE)
if [ $lastFlag -ne $currentFlag ]; then
echo "sendmail failed"
echo "1" > $TMPFILE
fi
else #Ping Ok
echo "Ping Ok"
currentFlag=0
lastFlag=$(cat $TMPFILE)
if [ $lastFlag -ne $currentFlag ]; then
echo "sendmail OK"
echo "0" > $TMPFILE
fi
fi

done
}

#Main
#echo $@
#echo $#
trap "rm lastcheck.tmp && exit" 1 2 15
case "$1" in
-h | --help) usage;;
*) action $@;;
esac

#Exit
exit 0

『声明:以上内容为本站网友《红男爵》原创,转载需征得原作者同意并注明转载自www.hlgnet.com』
2007-02-02 01:30:22   此文章已经被查看538次   
 相关文章: [回复]  [顶端] 



  您必须登录论坛才可以发表文章:
 
用户名:   密码:   记住密码:    (忘记密码 注册




版权所有 回龙观社区网 经营许可证编号:京B2-20201639 昌公网安备1101140035号

举报电话:010-86468600-5 举报邮箱: