I have the following shell script. It checks whether the python script is running or not, and if not, it will start the python script. When I run it from command line like ./crontab.sh it works even from other places like MaskRCNN/crontab.sh. But when I put it into the crontab only the echos are working.
#!/bin/bash
out=$(ps aux | grep 'python train/train.py' | rev | cut -d ' ' -f 1| rev | wc -l)
if [ $out -eq "2" ];then
echo "2 processes" >> /tmp/testing.txt
else
echo "1 process" >> /tmp/testing.txt;
cd /hdd1/Alex/testMaskRCNN_human_bodyparts/MaskRCNN_body;
CUDA_VISIBLE_DEVICES=0 /usr/bin/python train/train.py
fi
The crontab looks like this:
* * * * * /hdd1/Alex/testMaskRCNN_human_bodyparts/MaskRCNN_body/crontab.sh
I hope there are enough details. Thank you
asked Aug 9, 2017 at 12:58
Florentin Alexandru Iftimie
1091 silver badge5 bronze badges
2 Answers 2
try change train/train.py to full path...
Sign up to request clarification or add additional context in comments.
1 Comment
beliy
try also add ` > /tmp/cron.log` for loging output
I managed to debug it by adding the &>> operator.
`(/usr/bin/python /hdd1/Alex/testMaskRCNN_human_bodyparts/MaskRCNN_body/train/train.py &>> /tmp/testing.txt)`
And I found out that it missed an export:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
Final script:
#!/bin/bash
out=$(ps aux | grep '/usr/bin/python /hdd1/Alex/testMaskRCNN_human_bodyparts/MaskRCNN_body/train/train.py' | rev | cut -d ' ' -f 1 | rev | wc -l)
if [ $out -eq "2" ];then
echo "2 processes" >> /tmp/testing.txt
else
echo "1 process" >> /tmp/testing.txt
export CUDA_VISIBLE_DEVICES=0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
`(/usr/bin/python /hdd1/Alex/testMaskRCNN_human_bodyparts/MaskRCNN_body/train/train.py &>> /tmp/testing.txt)`
fi
answered Aug 10, 2017 at 15:39
Florentin Alexandru Iftimie
1091 silver badge5 bronze badges
Comments
default
CUDA_VISIBLE_DEVICES=0 /usr/bin/python train/train.pyis this supposed to run the script? because if it is i think the script needs to be surrounded by backticks/tmp/testing.txtget updated with 1's?