发布一个简单的ssh主机管理脚本

来到这边工作上的机器一直是ubuntu,没有发现有比较好的管理ssh帐号密码的工具,机器多了管理起来是比较蛋疼的。

俗话说的好,挠自己的痒处,于是就写了一个简单的小脚本,用于管理ssh主机。

项目截图:

[piglei@~]$ sshhelper 

usage:

    /usr/local/bin/sshhelper (hostname or short name)
    
    you can type a full hostname like 192.168.11.3 or a short name like 
    11.3 to ssh into it.
    
    - modify /home/piglei/.sshhelper_config to add your hosts.
    - available hosts:

        106.187.46.32        # CJ's linode
        192.168.111.51       # 4 twisted (py_raincounter)

[piglei@~]$ sshhelper 106
Start login into 106.187.46.32, please wait...

Last login: Mon Dec  5 05:51:35 2011 from 114.113.29.24
root@li389-32:~# 

 

主要功能及说明:

  • 使用了expect的python实现pexpect
  • 配置管理方面使用了configobj模块
  • 目前对于连接上的判断比较的粗糙,就是等候美元符号或者井号,这样做有的时候会出现问题(比如配置过的PS1)。但是翻过pxssh的源码发现他对于已连接上的判断也比较的不靠谱。
  • 支持跳板机设置,就是当指定的ip无法直接连接上的时候,会尝试使用你配置的跳板机进行连接(没办法,我这边的网络环境就这样)
  • 支持连接上以后依次执行设置好的命令
  • 最后,欢迎一起完善这个小脚本

 

项目地址:https://github.com/piglei/sshhelper