1

I wrote a script in python that does some stuff to some data in a MySQL server. Mostly just reducing unnecessary data. Currently, I need this to run once every 24 hours and I am achieving this by running it manually every day. Is there an easy way to automate this process on the actual server? I know how to do it on my computer by scheduling a task (windows) but I want this to run regardless of whether my computer is on or off.

1 Answer 1

1

Yes, you can use a cron job to run your script.

Here's a good tutorial but I'll put the important parts here https://gavinwiener.medium.com/how-to-schedule-a-python-script-cron-job-dea6cbf69f4e

On the command line enter crontab -e

Then add a line similar to this:

0 0 * * * /usr/bin/python3 /full/path/to/yourfile.py >> ~/cron.log 2>&1

Have a read of the link above, or google for some other cron job tutorials, to tweak this to your needs.

If your python script is mostly just running mysql statements, you might want to have a look at the mysql event scheduler too: https://dev.mysql.com/doc/refman/8.0/en/events-overview.html

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

1 Comment

@JustinOberle maybe take a look at event scheduling too, have added a link to the doc page

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.