Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure a script only runs after another script

Tags:

python

bash

cron

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.

like image 336
satoru Avatar asked Oct 28 '25 06:10

satoru


1 Answers

Wouldn't it be better to make a single cron job that runs ScriptA and then ScriptB? That way you can be sure that ScriptB doesn't run until ScriptA finishes, and you don't need to modify either script.

The cronjob could run a simple shell script like:

#!/bin/sh

python ScriptA.py
python ScriptB.py

Edit: If you really can't merge the two cron jobs, you could use the technique described in this question to wait for the first process to finish.

like image 100
srgerg Avatar answered Oct 31 '25 08:10

srgerg