Search code examples
pythondatecroncron-task

run python script once a month, pass parameters to script


Hi to everybody and thanks in advance for the help.

I have a python script which is started via command line with a string like this one:

python example.py [start-date] [end-date] [fixed-param]

I would like to make it automatically run once a month (on ubuntu), but every month the [start-date] and [end-date] have to be different. The script downloads some data about the previous month, so if it runs, say, the 1st of may, it have to pass [start-date]='01-04-2017' adn [end-date]='30-04-2017'.

in my intentions the script would run every month without my intervention so i would need to set the dates as variables or something.

What would be the easiest solution to this?


Solution

  • Sounds like you should be using Crontab to automate the python script running. For info on how to get started with Crontab, look here:

    Crontab how to

    Check out these two previous stack overflow questions for info on how to pass parameters and set a date variable in crontab:

    passing parameters to a python script with crontab

    date variables in crontab