I have two python scripts running as cronjobs.
ScriptA processes log files and insert records to a table, ScriptB uses the records to generate a report.
I have arranged ScriptA to run one hour before ScriptB, but sometimes ScriptB run before ScriptA finish inserting, thus generating a incorrect report.
How do I make sure ScriptB runs right after ScriptA finishes?
EDIT
ScriptA and ScriptB do very different things, say, one is for saving user data, the other is for internal use. And somewhere else there maybe some ScriptC depending on ScriptA.
So I can’t just merge these two jobs.
One approach would be to make sure that if those two jobs are separate cron jobs – there is enough time inbetween to surely cover the run of job 1.
Another approach is locking, as others here suggested, but then note, that cron will not re-run your job just because it completed unsuccessfully because of a lock. So either job2 will have to run in sleep cycles until it doesn’t see the lock anymore, or on the contrary sees a flag of job 1 completions, or you’ll have to get creative.
Why not to trigger 2nd script from the 1st script after it’s finished and make it a single cron job?