1

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

2 Answers 2

4

For append (you never want to cut the file), use >>; to get the stderr too, use 2>&1

exec /usr/bin/python /home/jhon/workspace/producer/test.py >> output 2>&1

and

import time
import sys

for i in range(100):
    time.sleep(1)
    sys.stdout.write('a'*i)
    sys.stdout.flush()
Sign up to request clarification or add additional context in comments.

Comments

3

Replace 1>&2 output with > output 2>&1:

 exec /usr/bin/python /home/jhon/workspace/producer/test.py > output 2>&1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.