I'm trying to write a simple shell script to start and stop my python script. The reason I'm doing this is because I want to use tool called monit to monitor processes and I also would need to be sure that this script is running. So here is my python script:
test.py
import time
for i in range(100):
time.sleep(1)
print 'a'*i
and here is my shell script:
wrapper_test.sh
#! /bin/bash
PIDFILE=/home/jhon/workspace/producer/wrapper_test.pid
case $1 in
start)
echo $$ > ${PIDFILE};
exec /usr/bin/python /home/jhon/workspace/producer/test.py 1>&2 output
;;
stop)
kill `cat ${PIDFILE}`
;;
*)
echo "Usage: wrapper {start|stop}"
;;
esac
exit 0
The result that I want is lets say I do tail -f output and I would see staff coming to the file. I also tried to change 1>&2 to just > but this creates file, and once I press Ctrl + C than all the data appends to the file.
But right now, I dont see anything