This question already has an answer here:
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
Since ssh returns with exit status of the remote command check man page for ssh and search for exit status
so Its as simple as
You do not need ps or grep for this
First of all httpd is not available in ubuntu. For ubuntu apache2 is available.
So this command
ps aux | grep [h]ttpd
will not work on ubuntu.No need to write any script to check the apache status. From ubuntu terminal run this command to get the status:
Output will be:
A > if apache is running:
Apache2 is running (pid 1234)
B > if apache is not running:
Apache2 is NOT running.
You are not running the commands on the remote host.
Try this instead.
Just to be explicit,
ps aux
is the argument tossh
and so that is what is being executed on the remote host. Thegrep
runs as a child of the local script.Try the following:
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 ).