我从以下开始:
auth = steelhead.CLIAuth(username=args.username, password=args.password)
sh = steelhead.SteelHead(host=192.168.1.2, auth=auth)
f = open('commands.txt')
for command in f:
print sh.cli.exec_command(command)
f.close()
这很好用。我在commands.txt中有两个命令,然后我将两个命令都输回。
接下来,我想实现一个ip.txt,用户可以将所有机器的所有IP放在我们想要在commands.txt中运行命令的地方。
我试过了:
h = open('appliances.txt')
for appliance in h:
auth = steelhead.CLIAuth(username=args.username, password=args.password)
sh = steelhead.SteelHead(host=appliance, auth=auth)
f = open('commands.txt')
for command in f:
print sh.cli.exec_command(command)
f.close()
h.close()
我在appliances.txt中只有一个IP,但我希望看到command.txt中两个命令的输出,就像我在添加appliances.txt循环之前一样。
不幸的是我只看到commands.txt中第一个命令的输出,秒似乎没有被执行。