调度Python脚本以在特定时间运行

时间:2016-06-30 19:49:32

标签: python

我编写了一个监视不同服务器上服务状态的函数。这是代码:

def heathcheck(server_address, service_name):

try:
    shell = spur.SshShell(hostname=server_address,
                      username ='abc',
                      password ='xyz', missing_host_key=spur.ssh.MissingHostKey.accept, connect_timeout=100)

    with shell:
        result = shell.run(['service', service_name, 'status'])
    print '%s on host : %s' % (result.output, server_address)
except spur.RunProcessError as e:
    print e.stderr_output
except IOError as e:
    print e.message
except Exception as e:
    print e.message
return '%s on host on thread : %s' % (result.output, server_address)

我想每天在特定时间运行此脚本。我正在使用这一小段代码:

schedule.every(2).minutes.do(heathcheck('server_address', 'httpd'))

while True:
    schedule.run_pending()
    time.sleep(10)

但即使我遵循了正确的示例(https://github.com/dbader/schedule/blob/master/FAQ.rst),我也会继续发现此错误:

TypeError: the first argument must be callable

知道问题可能是什么? 我正在使用https://github.com/dbader/schedule模块

0 个答案:

没有答案