I have the same syntax error when runnng your code. It turns out that
result is not a simple number, but contains a carriage return and line feed. To confirm this, pipe
result into
od -cx.
Perhaps this is related to the -n and -t options. Didn't check.
Thus, you need to tweak the ssh command on the first line.
Rather than counting the lines, leave out the wc command and just check $? after the first ssh. If $? is 0, httpd is running. If non-zero, it's not running.
EDIT: It
is related to -n -t, though I can't say exactly how.
EDIT2: Rather than checking $?, you can just write
Code:
if ssh username@$remotetarget $(ps|grep|grep))
then
echo "http is running"
else
echo "it's not running"
fi
You can also replace the ps pipe with a
service httpd status >/dev/null or
systemctl status httpd >/dev/null or whatever makes sense on the remote system.