擅长:python、mysql、java
<p>您可能想<a href="http://docs.python.org/2/library/threading.html#thread-objects" rel="nofollow">thread</a>您的电话。我准备了一个小示例,它只是回响一些东西(您可以将其更改为ssh)。我希望它足够清楚,这样你就能明白了</p>
<pre><code>#!/usr/bin/env python
import threading
import os
import random
ips = ["192.168.1.25", "192.168.1.26", "192.168.1.27"]
def run(ip, otherParameter):
os.system("echo %s with other parameter %s" % (ip, otherParameter))
if __name__ == "__main__":
for ip in ips:
thread = threading.Thread(target=run, args=[ip, random.randint(0, 10)])
thread.run()
</code></pre>
<p>同时,代替操作系统,您应该看一下<a href="http://docs.python.org/2/library/subprocess.html" rel="nofollow">subprocess</a>模块,或者更好的是,要想使用运行ssh命令的东西,请看一下<a href="http://www.lag.net/paramiko/" rel="nofollow">paramiko</a>模块。在</p>