开发者

Trying to make a script check apache status

开发者 https://www.devze.com 2023-04-06 14:12 出处:网络
So here is my bash script. APACHECHECK=\"$which telnet localhost 80\" echo -e \"\\n Checking APACHE\\n\"

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

精彩评论

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