Crontab to run a bash script that runs multiple python scripts

Tara Sutjarittham

I'm a beginner in linux. I want run multiple python scripts every 30 second and I'm planning to do this using a bash script ( to run multiple python scripts simultaneously) and crontab (to schedule the scripts to run every 30 sec).

This is how my bash script:

#!/bin/bash
# This script is used to run multiple python script to query all types and all modes of GTFSR data

#Set working directory
cd "${0%/*}"

#BUS Query Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/buses' --database="postgresql://localhost/test" —apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &

#Sydney Train Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &

#Ferries Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &

#lightrail Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &

#nswtrains Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &

This is what I put in crontab:

# GTFSR to Database
* * * * * ( /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
* * * * * ( sleep 30 ; /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)

If I run /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call manually, the bash script works fine. However nothing happens when the job is run via CRONTAB.

Please help.

Cheers!

Joe

Make sure you are creating the cron entries as root. I have had that get me in the past.

Verify your env variables and the python interpreter.

Make sure all the scripts are executable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Run multiple python scripts concurrently

Crontab using incorrect version of Python to run script

Run Multiple Powershell Scripts Sequentially - on a Folder - Combine Scripts into a Master Script

Ubuntu 16, Run Python script with Crontab

crontab failed to run python script at reboot

struggle to run python script with crontab

crontab does not run my python script

How to run multiple Python/Shell scripts from one script

FileNotFoundError while using crontab to run Python script

Unable To Get Crontab To Run Bash Scripts

Python script in bash with crontab doesn't work but without crontab it does

How to run sql scripts serially in bash script?

Google Script Run ClockTrigger Multiple Scripts

Crontab, python script fails to run

How to run multiple scripts each of which runs forever through one script?

Crontab runs /etc/init.d/ scripts but won't run service restart?

Cannot run a python script using crontab

Bash run multiple Python scripts with pre-imported modules

How to run Bash Script in Crontab on Raspbian?

Crontab runs bash in a different way

Bash script runs in shell, gives "not found" error in crontab

shell scripts runs manually but not in crontab

Run 2 python scripts using crontab

Crontab unable to run scripts?

Is there a way to run multiple bash scripts with one script at the same time?

How to run multiple scripts in a python script with args

python run multiple scripts

Cron activate virtualenv and run multiple python scripts from shell script

Bash Run Script on Multiple Files