我是linux的初学者。我希望每30秒运行多个python脚本,我打算使用bash脚本(同时运行多个python脚本)和crontab(安排脚本每30秒运行一次)来执行此操作。
这是我的bash脚本:
#!/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 &
这是我在crontab中的内容:
# GTFSR to Database
* * * * * ( /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
* * * * * ( sleep 30 ; /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
如果我手动运行/bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call
,bash脚本运行正常。但是,当作业通过CRONTAB运行时没有任何反应。
请帮忙。
干杯!
答案 0 :(得分:0)
答案 1 :(得分:0)
确保以root身份创建cron条目。我曾经让我过去。
验证你的env变量和python解释器。
确保所有脚本都是可执行的。