开发者

Trying to make a script check apache status

So here is my bash script.

APACHECHECK="$which telnet localhost 80"

echo -e "\n Checking APACHE\n"

$($APACHECHECK)

#if [[ $($APACHECHECK) == *Connected* ]]; th开发者_如何学编程en
#
#       echo -e "Apache is running on port 80 :)"
#               else
#                       echo -e "\n Apache is down!"
#               fi
#

Ignore the comments. The script runs telnet localhost 80. If it returns "Connected" then it reports that apache is running.

The problem is the script isn't fully running. Here is output of my script:

root@vr6 [~]# ./megatool 

 Checking APACHE

telnet: connect to address ::1: Connection refused

Here is me running telnet localhost 80

root@vr6 [~]# telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Also I would like to suppress output and just have my script report the echo of apache is running or its not like my if then statement.

Any ideas?


Why not use apachectl? It comes with apache and lets you do this:

apachectl status


To help with the telnet solution:

if telnet localhost 80 </dev/null 2>&1 | grep -q Connected; then
  echo "Connected"
else
  echo "no connection"
fi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜