0

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 ....

3
  • I think you need to look your OS facilities for doing something like crontab. You should be able to send current time as argument. For example echo `date` Commented Dec 10, 2017 at 16:32
  • 1
    @Nishant That's a useless use of echo Commented Dec 11, 2017 at 4:42
  • @tripleee Thanks for pointing out that link. Just wanted to point out the use of backtick, didn't find a better example ;) Commented Dec 11, 2017 at 4:53

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

4 Comments

honestly i don't know much crontab , how is it done this process ? like how i can pass the date argument to this 'crontab' from the other machine and pass it to the script dynamically ?
How do the machines communicate? Your question sounds like you want to automate this; so run the automation on the "controller" machine and have it submit tasks to the other machines by whatever mechanism you already use to communicate between them.
they use a simple connexion like we all aware of , such as socket or any other way , the important is that they both connect to the same server and what i want is that for each 5 minutes the first machine send to the server the current date and then execute automaticlly that script using the given date (from the first machine) as parameter to execute it on the seconde machine , i insist on the automatic term
Please edit your question to specify in more detail what code needs to run on which host and in which order, and how the hosts then communicate with each other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.