Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查远程进程是否正在运行(linux)_Linux_Ssh_Process - Fatal编程技术网

检查远程进程是否正在运行(linux)

检查远程进程是否正在运行(linux),linux,ssh,process,Linux,Ssh,Process,我有以下代码来检查脚本(名为my_script.sh)是否正在运行: ps cax | grep my_script.sh > /dev/null if [ $? -eq 0 ] then echo "Process is running." else echo "Process is not running." fi 但是,我想修改它来检查进程是否在另一台机器上运行,而不直接使用ssh,因为如果我在循环中运行它,这会使我脱离当前脚本 本质上,我想这样做: ssh oth

我有以下代码来检查脚本(名为
my_script.sh
)是否正在运行:

ps cax | grep my_script.sh > /dev/null
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi
但是,我想修改它来检查进程是否在另一台机器上运行,而不直接使用ssh,因为如果我在循环中运行它,这会使我脱离当前脚本

本质上,我想这样做:

ssh otherMachine
ps cax | grep my_script.sh > /dev/null
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi
ssh originalMachine

任何帮助都将不胜感激。谢谢

我不确定这是否是您想要的,但是您可以在ssh调用中直接在远程机器中执行check命令。返回值应与远程计算机中调用的命令的返回值相对应

当然,您需要启用无密码身份验证方法(例如ssh密钥)


这是检查程序是否在远程位置运行的简单解决方案

sshroot@192.168.22.12-p22-t“pgrep-fl while.sh”


将脚本复制到
otherMachine
并作为
ssh otherMachine check\u script运行。sh
@Jakuje我想将脚本保留在
originalMachine
上,因为最终的计划是在
originalMachine
上执行其他脚本,因为进程没有在
otherMachine
上运行。你的确切意思是什么通过“如果我在循环中运行当前脚本,这将使我脱离当前脚本”?你是说远程ssh连接没有结束吗?
ssh otherMachine "ps cax | grep my_script.sh > /dev/null"
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi
if [ $? -eq 0 ]; then echo "Process is running."; else   echo "Process is not running."; fi