I am running my python script using a shell script run.sh to restart it if crashes :
#!/bin/sh
COMMAND='nohup python3 -u test.py run >> py.log &'
LOGFILE=restart.txt
writelog() {
now=`date`
echo "$now $*" >> $LOGFILE
}
writelog "Starting"
while true ; do
$COMMAND
writelog "Exited with status $?"
writelog "Restarting"
done
I'm running
nohup sh -u run.sh > output&
The problem is python would only stream the first output(print()) to py.log. How can I get out the output streamed instantly. I have also tried COMMAND=./test.py run >> py.log & . I would appreciate the help. Thank you.
&at the end of theCOMMAND? That causes the command to background>>in the string is not understood as a redirection, your python script must be getting>>andpy.logas parameters.&or not it doesn't work @iruvarpy.log. but only the first line. Next outputs are not streamed .