实时监听服务器端口状态

#!/bin/bash
monitor()
{
  sudo lsof -i:Port
  t=$?
  if [  $t -eq 0  ] ; then
    echo "The Server is working"
  fi
  if [  $t -eq 1 ] ;then
    echo "The Server is down "
    date;ls;df
  fi
}

while :
do
monitor
sleep 5

done

其中

1、sudo  lsof -i :port查看端口信息

2、$?表示上一次程序或脚本的退出码,成功值为0,不成功为非0!

你可能感兴趣的:(linux)