Reputation: 71
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?
Upvotes: 0
Views: 896
Reputation: 5492
You may not be seeing any output from tail
because the result of your arithmetic for the -n
argument may be 0:
anew@Wintermute:work$ wc -l dev-configuration.json
105 dev-configuration.json
anew@Wintermute:work$ tail -n 0 dev-configuration.json
anew@Wintermute:work$
Upvotes: 1