简体   繁体   中英

execute and run script python on a server several times

I have a script in python that takes date as an argument in order to get the event in google agenda using google API calendar at that date. Now my problem is as follows: There are three machines: first one is doing some treatment in order to get a date for some reason, second machine is the server that the two other machines are connected to, third machine is where i have to execute the script python in order to get event of its google calendar.

So my question is how can I do such that for every 5 minutes - the first machine send the date (that means every 5 minutes i get a different date ) and each date I get I have to execute that script python to get the event on that date and send the answer to the first machine (doing it dynamically and the server is in the middle between the two other machines ). In other words, how can I make this process dynamic such that for every 5 minutes the script python has to be executed using for each time a different date and give back the result?

I want to execute the script like this :

python script.py '2017-12-10 10:40:00'   #(first time)

python script.py '2017-12-10 10:45:00'   #(after 5 minutes)

python script.py '2017-12-10 10:50:00'   #(after another 5 minutes)

and so on ....

With a crontab entry like

*/5 * * * * python path/to/script.py "$(date %%F %%T)"

where the path/to is relative to your home directory, and the */5 is a Vixie cron (in practice, more or less Linux only) extension which might not work on other platforms. The crontab format requires the percent signs to be doubled -- maybe put this in an external script if you need complex expressions with many percent signs.

There is no guarantee that this runs exactly on the second, or even on the minute. Maybe use %%H:%%M:00 instead of %%T to force the seconds (forcing the minutes will be slightly more challenging; again, maybe put the logic in an external script if you need this).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM