编写脚本以检查远程主机服务是否正在运行 [英] Write the script to check remote host services running or not

查看:237
本文介绍了编写脚本以检查远程主机服务是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是脚本,但是即使Apache正在运行其show stop,输出也是错误的.我正在使用Ubuntu 12.04.

This is the script but output is wrong even Apache is running its show stop. I'm using Ubuntu 12.04.

ssh -qn root@ ip

if ps aux | grep [h]ttpd > /dev/null
then
    echo "Apcache is running"
else
    echo "Apcahe is not running"

fi

推荐答案

尝试以下操作:

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用户一起运行

这篇关于编写脚本以检查远程主机服务是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆