Reputation: 191
I have the following bash script:
#!/bin/bash
set command "pgrep -x 'gedit' "
ssh -t [email protected] $command
Now, I want to include this as well in the other device:
if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi
How can I make the IF Statement run on the other device? I wasn't able to include it in the ssh.
I tried this:
set command "pgrep -x 'gedit' "
ssh -t [email protected] '
if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi'
But it didn't work! maybe because there is no command at the beginning?
Thanks.
Upvotes: 1
Views: 182
Reputation: 784938
Invoke bash
with heredoc:
ssh -t [email protected] bash <<EOF
if pgrep -x "gedit" > /dev/null
then
echo "Running"
else
echo "Not Running"
fi
EOF
Upvotes: 2