0

I want a Python program to execute on scheduled or regular intervals using terminal, using mac system but solutions are acceptable for Windows also.

Below is the steps that i want to achieve.

step 1) Open terminal and enter : sudo start --init**
        it will prompt to enter user name: usr_name
        password '-------------'

       step 2) after that run this command

        function params1 --params2 “value”

        step 3) After 3 to 4 minutes run the same program
          , It will ask for killing the previous session and will ask to enter users master password.

        or if we can do it in the same terminal press control+C 
, it will end the current session and bring the terminal to next line 
, then again the command function params1 --params2 “value”
,If we are doing this there will be no need to enter the user name and password as in step 1

The below scripts are not working.In command line it is working out well but it need to be automated and scheduled.The scheduling is the issue.

Any help or suggestions please.

import sys
import subprocess
import os
import openpyn
#sys.path.insert(1, ‘/Users/klr/Downloads/nordvpnipchange/openpyn/openpyn.py’)
#subprocess.check_output([‘ls’,‘-l’])
#subprocess.check_output([‘sudo openpyn --init’])
os.system(“sudo openpyn --init”)
#print(os.system(“sudo openpyn --init”))
#print (subprocess.check_output([“sudo openpyn --init”]))

second one,

import subprocess
import os
subprocess.call(["openpyn DE --area “Berlin"], shell=True)
os.system("openpyn DE --area “Berlin")

Tried it with Automator in Mac as shown below,But don't know how we can schedule it.

enter image description here

Linu
  • 589
  • 1
  • 10
  • 23
  • What have you tried so far? – Marc Jan 29 '20 at 10:10
  • @Marc tried to do it with Python using subprocess and os.system to pass the statements as command line arguments but didn't worked it out. Also tried it with this link https://github.com/jotyGill/openpyn-nordvpn,Using this have updated the package,if we manually try it will work in terminal window. – Linu Jan 29 '20 at 17:28
  • @Marc Edited my question .Can you please help. – Linu Jan 29 '20 at 17:32
  • have you seen this?: https://stackoverflow.com/a/13045700/5516057 – Marc Jan 29 '20 at 20:50

1 Answers1

0

Try using a Cron Job. Here's a guide on how to get started.

Cron jobs are really popular for scheduling the running of scripts and automating stuff.

Jamie
  • 1,530
  • 1
  • 19
  • 35