I have a script that I use for iperf to be able to start, stop, and check the status of it like a typical service. If I issue a "service iperf start" or a "service iperf stop" it works correctly. When I try to issue a "service iperf status" it always returns it as running even though its not.
When running:
#service iperf status
/usr/bin/iperf pid 37567 is running!!!
When not running:
# service iperf status
/usr/bin/iperf pid is running!!
Here is my entire script:
#!/bin/bash
# chkconfig: - 50 50
# description: iperf
DAEMON=/usr/bin/iperf
service=iperf
info=$(pidof /usr/bin/iperf)
is_running=`ps aux | grep -v grep | grep iperf | wc -l | awk '{print $1}'`
case "$1" in
start)
$DAEMON -s -D
;;
stop)
pidof $DAEMON | xargs kill -9
;;
status)
if [ $is_running != "1" ];
then
echo $DAEMON pid $info is running!!!
else
echo $DAEMON is NOT running!!!
fi
;;
restart)
$DAEMON stop
$DAEMON start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
It seems like its not able to read past the first echo statement in the status section of the script. I have ran the ps command outside of the script from command line to verify I am getting the correct output. If the service is running it returns a "1" just like the script checks for. If its not running it returns a "0" so it should move on to the next echo statement but its not. Can anyone tell me how to fix this?
I am on RHEL 6.7 bash version 4.1.2