Python-连续循环执行功能

这里的Python新手,请原谅不好的编码做。

当我运行以下.....

def bug_check():
        for host in hosts:
            sshInteract.send('ssh ' + host )
            try: 
                sshInteract.expect(ep1)
                sshInteract.send(password)
                sshInteract.expect(ep2)
            except: 
                print("SSH unsuccessful")
            else:
                sshInteract.send("exit")
                sshInteract.expect(ep3)
                print("SSH successful")

bug_check()  

...基于列表中的三台主机,我得到的打印输出(正确)是:

SSH successful
SSH successful
SSH unsuccessful

我想做的是每60秒连续运行一次,直到我手动停止它为止。所以我做了以下事情:

def bug_check():
        for host in hosts:
            sshInteract.send('ssh ' + host )
            try: 
                sshInteract.expect(ep1)
                sshInteract.send(password)
                sshInteract.expect(ep2)
            except: 
                print("SSH unsuccessful")
            else:
                sshInteract.send("exit")
                sshInteract.expect(ep3)
                print("SSH successful")

while True:
    bug_check()
    time.sleep(60) 

运行此命令时,打印输出看起来像这样,这是不正确的:

SSH successful
SSH successful
SSH unsuccessful
SSH unsuccessful
SSH unsuccessful
SSH unsuccessful
SSH unsuccessful
SSH unsuccessful
SSH unsuccessful

它应该是什么样的:

SSH successful
SSH successful
SSH unsuccessful
SSH successful
SSH successful
SSH unsuccessful
SSH successful
SSH successful
SSH unsuccessful

我在这里做错了什么?

评论