更复杂的IO – Backgrounding
回到我们膳绫擎的“监控多台办事器”的例子上来。想象一下,我们要在每台办事器上运行一个长时光运行的义务。默认情况下,ShutIt会持续运行很长时光。然则我们可以在后台运行义务来加快ShutIt的运行速度。
- import shutit
- import time
- long_command="""sleep 60"""
- session1 = shutit.create_session('bash')
- session2 = shutit.create_session('bash')
- password1 = session1.get_input('Password for server1', ispass=True)
- password2 = session2.get_input('Password for server2', ispass=True)
- session1.login('ssh you@one.example.com', user='you', password=password1)
- session2.login('ssh you@two.example.com', user='you', password=password2)
- start = time.time()
- session1.send(long_command, background=True)
- session2.send(long_command, background=True)
- print('That took: ' + str(time.time() - start) + ' seconds to fire')
- session1.wait()
- session2.wait()
- print('That took: ' + str(time.time() - start) + ' seconds to complete')
我的标记本电脑说,运行这两个敕令只需花费0.5秒,而脚本在一分钟今后才运行停止(应用了’wait’办法)。
固然这个例子看起来是眇乎小哉的,然则想像一下,如不雅你稀有百台如许的办事器须要治理,那么你可以看到这几行代码和一个python import所带来的强大年夜的力量。
更复杂的IO – Expecting
更多信息
ShutIt可以做很多事。更多信息,请参阅:
- ShutIt (https://ianmiell.github.io/shutit/)
- GitHub (https://github.com/ianmiell/shutit/blob/master/README.md)
推荐阅读
本月19日在北京举办的 LC3 大年夜会 (LinuxCon + ContainerCon + CloudOpen)应当是全球最顶级的开源大年夜会了,而这一为期两天的开源嘉会以前几年在北美、欧洲和日本都举办过,而此次是其初次来到中国。就在同一天>>>详细阅读
本文标题:ShutIt:一个基于Python的shell自动化框架
地址:http://www.17bianji.com/lsqh/35881.html
1/2 1