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.

2 Answers2

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

nickmana
  • 71
  • 3
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.
Ed Behn
  • 450
  • 2
  • 10