automation - How to execute python script on schedule? -
i have 2 python scripts
on machine want execute 2 times day on specific time period. how automate task? since away home , computer while, want upload them site , executed there automatic without me doing anything.
how can this?
you can use cron
if on linux machine. cron system daemon used execute specific tasks @ specific times.
cron
works on principle of crontab
, text file list of commands run @ specified times. follows specific format, can explained in detail in man 5 crontab
format crontab
each of sections separated space, final section having 1 or more spaces in it. no spaces allowed within sections 1-5, between them. sections 1-5 used indicate when , how want task executed. how cron job laid out:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = sunday), command
01 04 1 1 1 /usr/bin/somedirectory/somecommand
the above example run /usr/bin/somedirectory/somecommand @ 4:01am on january 1st plus every monday in january. asterisk (*) can used every instance (every hour, every weekday, every month, etc.) of time period used. code:
01 04 * * * /usr/bin/somedirectory/somecommand
the above example run /usr/bin/somedirectory/somecommand @ 4:01am on every day of every month.
comma-separated values can used run more 1 instance of particular command within time period. dash-separated values can used run command continuously. code:
01,31 04,05 1-15 1,6 * /usr/bin/somedirectory/somecommand
the above example run /usr/bin/somedirectory/somecommand
@ 01 , 31 past hours of 4:00am , 5:00am on 1st through 15th of every january , june.
the "/usr/bin/somedirectory/somecommand" text in above examples indicates task run @ specified times. recommended use full path desired commands shown in above examples. enter somecommand in terminal find full path somecommand. crontab begin running edited , saved.
you may want run script number of times per time unit. example if want run every 10 minutes use following crontab entry (runs on minutes divisible 10: 0, 10, 20, 30, etc.)
*/10 * * * * /usr/bin/somedirectory/somecommand
which equivalent more cumbersome
0,10,20,30,40,50 * * * * /usr/bin/somedirectory/somecommand
Comments
Post a Comment