如何在UNIX中传递IF语句到SSH ?



我有以下bash脚本:

# !/bin/bash

set command "pgrep -x 'gedit' "
ssh -t  test@192.168.94.139 $command

现在,我想把这个也包含在另一个设备中:

if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi

如何在其他设备上运行IF语句?我无法将它包含在ssh.

我试过了:

set command "pgrep -x 'gedit' "
ssh -t  test@192.168.94.139 '
if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi'

但它没有工作!也许是因为一开始就没有命令?

谢谢。

调用bash:

ssh -t test@192.168.94.139 bash <<EOF
if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi
EOF

最新更新