I want to iterate through a list of bash scripts with a cron-job. I.e. every two hours I want to start another bash script. My idea was to set a new environment variable, each time the cronjob script reads this environment variable and calls the corresponding script and and increments the environment variable.
I tried this, and it works if I call test.sh
from the terminal.
# test.sh
JOB_COUNTER=$((JOB_COUNTER + 1))
echo $JOB_COUNTER
export JOB_COUNTER=$JOB_COUNTER
If I put call it from within crontab
, $JOB_COUNTER
does not seem to get incremented (I check it with echo $JOB_COUNTER
)
Context: I want to add 50 new jobs to our cluster every two hours, because if I would submit all jobs together, the scheduler does start too many jobs in parallel and most time out because the I/O is too slow. If a cronjob is not what one would use, I am open for other ideas.