I have a cgi script running but I am having issues with the cgi script not waiting for all of the output of the commands.
Here is the cgi script:
#!/bin/bash
echo Content-type: text/plain
echo ""
case "$QUERY_STRING" in
start)
service servicename start
;;
stop)
service servicename stop
;;
restart)
service servicename restart
;;
backup)
service servicename backup
;;
checkisup)
service servicenamet checkisup
;;
status)
service servicename status
;;
*)
echo "Usage: $0 {checkisup|start|stop|restart|backup|status|restart}"
exit 1
;;
esac
exit 0
When i call the status with script.cgi?status
it executes the status function form my service
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
pre_log_len=`wc -l "$PATH/server.log" | awk '{print $1}'`
echo "$SERVICE is running... executing command"
as_user "screen -p 0 -S screenname -X eval 'stuff \"$command\"\015'"
sleep .1
tail -n $[`wc -l "$PATH/server.log" | awk '{print $1}'`-$pre_log_len] "$PATH/server.log"
fi
The part i am having the issue with is when the function gets to sleep .1 the cgi script will just continue without waiting for the output of tall.
Any ideas?
sleep .1, maybe good for a working system, but can't help in debugging this situation. Trysleep 10and see if that changes things. Good luck!