且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

编写脚本以检查远程主机服务是否正在运行

更新时间:2023-12-05 11:15:22

尝试以下操作:

if ssh -qn root@ip pidof httpd &>/dev/null ; then
     echo "Apache is running";
     exit 0;
else
     echo "Apache is not running";
     exit 1;
fi

这些exit命令也会发送正确的 EXIT_SUCCESS EXIT_FAILURE (如果需要,将来可用于扩展此脚本).

These exit commands will send the correct EXIT_SUCCESS and EXIT_FAILURE too ( Will be usefull to extend this script in future, if you need ).

但是有一个建议:***将脚本作为远程进程使用ssh帐户与sudoer用户一起运行