0

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

12
  • CUDA_VISIBLE_DEVICES=0 /usr/bin/python train/train.py is this supposed to run the script? because if it is i think the script needs to be surrounded by backticks Commented Aug 9, 2017 at 13:02
  • permission issue? might be chmod 777 crontab.sh would work Commented Aug 9, 2017 at 13:09
  • @Nullman Just tried that and it doesn't help :( Commented Aug 9, 2017 at 13:29
  • @ggupta neither that doesn't work Commented Aug 9, 2017 at 13:30
  • does you /tmp/testing.txt get updated with 1's? Commented Aug 9, 2017 at 13:34

2 Answers 2

1

try change train/train.py to full path...

Sign up to request clarification or add additional context in comments.

1 Comment

try also add ` > /tmp/cron.log` for loging output
0

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

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.