#!/bin/sh
checkPort()
{
telnet $2 $3 /dev/null
^]
close
!
ss=`cat checkPort.log | grep "Escape character is"`
if [ "A$ss" = "A" ]
then
echo "$2 port $3 checking result at `date` is not available">>checkingResult.log
#printf "$1 telnet $2 . $3 port "
#printf '\033[7m'
#printf "not available\n"
#printf '\033[m'
return 1
else
echo "$2 port $3 checking result at `date` is available">>checkingResult.log
#printf "$1 telnet $2 . $3 port "
#printf "available\n"
return 0
fi
}
checkPort 10.253.32.25 10.253.35.14 10000
Linux一个简单的每秒执行命令shell脚本
如果需要该脚本每秒执行一次命令,通过linux自带的cron却不能实现,新版的cron据说可以精确到秒。
修改shell脚本:
#!/bin/bash
checkPort()
{
telnet $2 $3 /dev/null
^]
close
!
ss=`cat checkPort.log | grep "Escape character is"`
if [ "A$ss" = "A" ]
then
echo "$2 port $3 checking result at `date` is not available">>checkingResult.log
#printf "$1 telnet $2 . $3 port "
#printf '\033[7m'
#printf "not available\n"
#printf '\033[m'
return 1
else
echo "$2 port $3 checking result at `date` is available">>checkingResult.log
#printf "$1 telnet $2 . $3 port "
#printf "available\n"
return 0
fi
}
while [ true ]; do
/bin/sleep 1
checkPort 10.253.32.25 10.253.35.14 10000
done
放入后台运行即可