繁体   English   中英

主机Ping服务启动脚本?

[英]Host Ping Service Start script?

我需要Linux Shell脚本的帮助,该脚本应自动检查主机是否可访问。 最好每3-5秒ping端口22。 如果端口可访问,程序应执行命令服务HelloWorld stop。 如果无法访问主机,则脚本应在计算机上自动执行命令,例如服务HelloWorld start。

有人知道如何实现吗?

我有类似的东西,但是没有起作用,

#!/bin/bash
IP='192.168.1.1'
fping -c1 -t300 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
  service helloworld stop
else
  service helloworld start
fi

试试下面的代码

#!/bin/bash
IP='192.168.1.1'
PORT=22
(echo >/dev/tcp/$IP/$PORT) &>/dev/null
if [ "$?" = 0 ]
then
  service helloworld stop
else
  service helloworld start
fi

这样,可以检查特定端口的IP是否可达

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM