linux 登陆服务器敲命令太多,某时候确实不便,所以就用shell写了一个
我的blog地址: http://www.CUOXin.com/caoguo
序号:ip:端口:用户:密码:说明 1:192.168.88.128:22:root:toor:虚拟机web服务器
github地址:https://github.com/ca0gu0/so
脚本下载:git clone git@github.com:ca0gu0/so.git
补充:
发现没有代码还是不好,把代码还是贴上
so.sh文件的内容
#!/bin/bashdirec=`dirname $0`function color(){ blue="/033[0;36m" red="/033[0;31m" green="/033[0;32m" close="/033[m" case $1 in blue) echo -e "$blue $2 $close" ;; red) echo -e "$red $2 $close" ;; green) echo -e "$green $2 $close" ;; *) echo "Input color error!!" ;; esac}function copyright(){ echo "#####################" color blue " SSH Login Platform " echo "#####################" echo}function underline(){ echo "-----------------------------------------"}function main(){while [ True ];do echo "序号 | 主机 | 说明" underline awk 'BEGIN {FS=":"} {PRintf("/033[0;31m% 3s /033[m | %15s | %s/n",$1,$2,$6)}' $direc/passWord.lst underline read -p '[*] 选择主机: ' number pw="$direc/password.lst" ipaddr=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $2}}' $pw) port=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $3}}' $pw) username=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $4}}' $pw) passwd=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $5}}' $pw) case $number in [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) echo $passwd | grep -q ".pem$" RETURN=$? if [[ $RETURN == 0 ]];then ssh -i $direc/keys/$passwd $username@$ipaddr -p $port echo "ssh -i $direc/$passwd $username@$ipaddr -p $port" else expect -f $direc/ssh_login.exp $ipaddr $username $passwd $port fi ;; "q"|"quit") exit ;; *) echo "Input error!!" ;; esacdone}copyrightmain
ssh_login.exp 这个一个expect脚本,用户写交互的工具
#!/usr/bin/expect -fset TARGET [lindex $argv 0]set USER [lindex $argv 1]set PASSWD [lindex $argv 2]set PORT [lindex $argv 3]set timeout 10spawn ssh $USER@$TARGET -p $PORTexpect { "*yes/no" {send "yes/r"; exp_continue} "*password:" {send "$PASSWD/r"}}interact
password.lst密码文件格式
1:192.168.88.128:22:root:toor:虚拟机web服务器2:192.168.88.130:22:ca0gu0:toor:虚拟机MySQL数据库服务器103:192.168.88.4:22:root:sellercube:本地开发服务器
新闻热点
疑难解答