top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Schedule a script for every two hours using Python Scheduling

+1 vote
776 views

I am Automating some repetitive works through Sikuli and Python scripting languages. I have multiple workflows. I need to schedule this script for every two hours. Can anyone guide me how to schedule the scripts for every two hours.

Is there any way to schedule the python programming through Task scheduler in windows platform.

My environment
OS:Windows
Programming languages: Sikuli,Python

posted Aug 7, 2015 by Ankit

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

The windows equivalent to a cron job is a scheduled task.

schtasks /create /tn calculate /tr calc /sc weekly /d MON /st 06:05 /ru "System"

Creates the task calculate, which starts the calculator(calc) every monday at 6:05 (should you ever need that.)

For your query you can try below:

schtasks create /tn python_file.py /sc hourly /st 12:00 /ry "System"

Using curl with cmd.exe in Windows 7 (or Vista) with Task Scheduler

  1. Start Computer Management (Windows Key, right-click Computer, select Manage...)
  2. In right column, select Create Job...
  3. Fill in General tab.
  4. Under Triggers tab, select New..., then set the desired schedule, with repeat set in Advanced Options.
  5. Under Actions tab, select Start a program, the program is CMD.EXE. For the optional argument, enter /C "curl [link provided on the status report page]".
answer Aug 7, 2015 by Amit Kumar Pandey
0 votes

If using Windows 7 then use Task Scheduler.

Go to Control Panel -> Administrative Tools -> Task Scheduler.

answer Aug 7, 2015 by Jagan Mishra
Similar Questions
0 votes

I am trying to use mitmproxy behind a company proxy that requires a user/password login.

The setup is: Local PC's browser -> mitmproxy (on local PC) -> company proxy -> internet.

Based on this SO thread, this is how you use mitmproxy within a Python program. This example works fine when there's no proxy.

from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster

class Addon(object):
    def __init__(self):
        pass

    def request(self, flow):
        # examine request here 
        pass

    def response(self, flow):
        # examine response here
        pass


if __name__ == "__main__":

    options = Options(listen_host='0.0.0.0', listen_port=8080, http2=True)
    m = DumpMaster(options, with_termlog=False, with_dumper=False)
    config = ProxyConfig(options)

    m.server = ProxyServer(config)
    m.addons.add(Addon())

    try:
        print('starting mitmproxy')
        m.run()
    except KeyboardInterrupt:
        m.shutdown()

Assuming the company proxy is at IP "1.2.3.4" port 3128 and requires a login USER and PASSWORD, how can I change this script to have mitproxy use that proxy instead of going to the internet directly?

Addition info: I am not using mitmdump with the script-parameter to run this script. The goal is to run this from Python 3.8 with a pip-installed mitmproxy

+5 votes

I am building my script. I want to run all the test scripts.

Currently I am running the code "python setup.py test", it is running only the some tests in my directory. I want to run all the tests in my directory.

0 votes

I'm trying to write a python script that writes some content to a file root through sudo, but it's not working at all. I am using:

 channel = 'stable'
 config_file = '/opt/ldg/etc/channel.conf'
 command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 out, _ = p.communicate()

But it seems as if this isn't doing anything.

I just want to write the contents of the variable channel to the file /opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can anyone offer any pointers?

+1 vote

Is there a way to make python script that connects to mySQL DB ask for a password on the:

conn = mdb.connect(host, user)
...