FlyingAtom FlyingAtom - 1 month ago 7
Linux Question

Bash running in sequence from Cronjob

#!/bin/bash
# My first script
sleep 15 & wait
python pythonFileName.py & wait
python pythonFileName.py & wait
python pythonFileName.py & wait


How do I get it to wait for the previous line to finish executing before moving to the next?

It work fine when you call the bash file directly , but when called from cronjob, it's executing everything without waiting for the previous one to finish.

Sleep works fine with this but for the py file, it's executing without waiting.
I also tried the following

A; B Run A and then B, regardless of success of A
A && B Run B if A succeeded
A || B Run B if A failed
A & Run A in background.

Answer

Are you sure python is in the path when running from cron? It's often the case that your cron job's environment is stripped down compared to your normal shell environment since it doesn't execute the normal environment setup scripts. Does it work if you specify the full path to python?

Comments