码迷,mamicode.com
首页 > 系统相关 > 详细

使用shell脚本自定义实现选择登录ssh

时间:2016-08-18 19:40:36      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

在系统bin目录中建立两个脚本分别是pssh tssh

pssh

#!/usr/bin/expect -f
set ip [lindex $argv 0 ]
set port [lindex $argv 1 ]
set password [lindex $argv 2 ]
set timeout 10
spawn ssh root@$ip -p$port
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$password\r" }
}
interact

 

tssh

#!/bin/sh
echo "以下是你的所有服务器列表"
echo "1.A服务器 192.168.100.11"
echo "2.B服务器 192.168.100.12"
echo "3.C服务器 192.168.100.13"
echo "0.暂时不想登录"
echo "请输入对应数字,选择你要登录的服务器:\c"
read input
test $input = 0

case $input in
1)pssh 192.168.100.11 22 123456;;
2)pssh 192.168.100.12 22 admin;;
3)pssh 192.168.100.13 22 root;;
esac

记得将给脚本加上可执行权限

 

然后在终端上执行tssh出现如下结果

以下是你的所有服务器列表
1.A服务器 192.168.100.11
2.B服务器 192.168.100.12
3.C服务器 192.168.100.13
0.暂时不想登录
请输入对应数字,选择你要登录的服务器:1
spawn ssh root@192.168.100.11 -p22
CentOS release 6.8 (Final)
Kernel \r on an \m
root@192.168.100.11‘s password:
Last login: Thu Aug 18 18:34:58 2016 from 192.168.100.2

Welcome to aliyun Elastic Compute Service!

[root@Official ~]#

 

使用shell脚本自定义实现选择登录ssh

标签:

原文地址:http://www.cnblogs.com/xiaozong/p/5785097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!