命令行自动打开多个命令窗口,并进入到指定的索引中,或者自动登录多台服务器
命令行自动打开多个命令窗口,并进入到指定的目录中,或者自动登录多台服务器
1.每次开机需要打卡多个命令窗口,登录到不同的服务器
可以使用一下方式,前提是 必须安装 guake,python
1.编写 python
#!/usr/bin/env python
import os
#pcList=['47','48','49','60','61','94']
#pcList=['151','152','153','154', '155','156']
pcList=['18','19','31']
for i in pcList:
os.system("guake -n 1")
os.system("guake -r %s"%i)
os.system("guake -e 'ssh root@172.16.236.%s'"%i)
import os
#pcList=['47','48','49','60','61','94']
#pcList=['151','152','153','154', '155','156']
pcList=['18','19','31']
for i in pcList:
os.system("guake -n 1")
os.system("guake -r %s"%i)
os.system("guake -e 'ssh root@172.16.236.%s'"%i)
将以上内容保存在 文件 startAll 中 ,给 startAll 提供可执行权限
sudo chmod +x startAll
2.启动 guake (将guake设置为开机启动)
3..在guake 的命令窗口中 执行 startAll (这里需要将确定登录目标机器不需要输密码,具体操作:参考 ssh 自动登录)
连接到远程服务器:
1 #!/usr/bin/env python
2 import os
3 #pcList=['47','48','49','60','61','94']
4 #pcList=['151','152','153','154', '155','156']
5 pcList=['151','152','153','154','155','156']
6 for i in pcList:
7 os.system("guake -n 1")
8 os.system("guake -r %s"%i)
9 os.system("guake -e 'ssh root@172.16.205.%s'"%i)
2 import os
3 #pcList=['47','48','49','60','61','94']
4 #pcList=['151','152','153','154', '155','156']
5 pcList=['151','152','153','154','155','156']
6 for i in pcList:
7 os.system("guake -n 1")
8 os.system("guake -r %s"%i)
9 os.system("guake -e 'ssh root@172.16.205.%s'"%i)
连接到远程服务器并且进入到指定目录:
1 #!/usr/bin/env python
2 import os
3 #pcList=['47','48','49','60','61','94']
4 #pcList=['151','152','153','154', '155','156']
5 pcList=['151','152','153','154','155','156']
6 for i in pcList:
7 os.system("guake -n 1")
8 os.system("guake -r %s"%i)
9 os.system("guake -e 'ssh root@172.16.205.%s'"%i)
10 os.system("guake -e cdpkg")
进入到本地目录:
1 #!/usr/bin/env python
2 import os
3 options=[
4 'parser',
5 'sender',
6 'control',
7 'tracer'
8 ]
9 for i in options:
10 os.system("guake -n 1")
11 os.system("guake -r %s"%i)
12 os.system("guake -e %s"%i)