1

I have python script for ssh which help to run various Linux commands on remote server using paramiko module. All the outputs are saved in text file, script is running properly. Now I wanted to run these script twice a day automatically at 11am and 5pm everyday.

How can I run these script automatically every day at given time without compiling every time manually. Is there any software or module.

Thanks for your help.

4
  • 1
    I think this question has to do more with your OS than with Python. What OS are you running? Commented May 6, 2016 at 20:16
  • 2
    Explore the cron daemon - for all your Unix scheduling needs Commented May 6, 2016 at 20:16
  • 1
    Possible duplicate of: stackoverflow.com/questions/373335/… Commented May 6, 2016 at 20:19
  • I am using Ubuntu Linux OS.. Commented May 6, 2016 at 20:22

2 Answers 2

5

If you're running Windows, your best bet would be to create a Scheduled Task to execute Python itself, passing the path to your script as an argument.

If you're using OSX or Linux, CRON is your friend. There are references abound for how to create scheduled events in crontab. This is a good start for setting up CRON tasks.

One thing to mention is permissions. If you're running this from a Linux machine, you'll want to ensure you set up the CRON job to run under the right account (best practice not to use your own).

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

Comments

0

Assuming you are running on a *nix system, cron is definitely a good option. If you are running a Linux system that uses systemd, you could try creating a timer unit. It is probably more work than cron, but it has some advantages.

I won't go though all the details here, but basically:

  • Create a service unit that runs your program.
  • Create a timer unit that activates the server unit at the prescribed times.
  • Start and enable the timer unit.

Comments

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.