Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3013687
  • 博文数量: 454
  • 博客积分: 4860
  • 博客等级: 上校
  • 技术积分: 6375
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 10:08
个人简介

10年工作经验,专研网站运维。

文章分类

全部博文(454)

文章存档

2017年(11)

2016年(13)

2015年(47)

2014年(36)

2013年(147)

2012年(64)

2011年(136)

分类: 系统运维

2016-10-09 09:43:48

Overview:
    You want to access server by SSH command quickly, you can use the script. you can write the server information into a file, and use the script involved the file.
Procedure:
    Make a document, for username, IP address, port, like this:
kobe@192.168.10.224:22
aaa@192.168.10.224:22
bbb@192.168.10.224:22

make a script:
#!/bin/bash
# Login system automatically by the script.
# Executing "sh login.sh 1" to login the first server.

port1=`awk -F ":" 'NR==1 {print $2}' /root/shell-script/aaa.txt`
server1=`awk -F ":" 'NR==1 {print $1}' /root/shell-script/aaa.txt`
port2=`awk -F ":" 'NR==2 {print $2}' /root/shell-script/aaa.txt`
server2=`awk -F ":" 'NR==2 {print $1}' /root/shell-script/aaa.txt`
port3=`awk -F ":" 'NR==3 {print $2}' /root/shell-script/aaa.txt`
server3=`awk -F ":" 'NR==3 {print $1}' /root/shell-script/aaa.txt`
case $1 in
1)
/usr/bin/ssh -p $port1 $server1
;;
2)
/usr/bin/ssh -p $port2 $server2
;;
3)
/usr/bin/ssh -p $port3 $server3
;;
list)
echo 1 is `sh test.sh | awk -F ":" 'NR==1 {print $1}'`
echo 2 is `sh test.sh | awk -F ":" 'NR==2 {print $1}'`
echo 3 is `sh test.sh | awk -F ":" 'NR==3 {print $1}'`
;;
*)
echo "Please enter 1, 2 or 3 ......."
echo 1 is `sh test.sh | awk 'NR==1 {print; exit}'`
echo 2 is `sh test.sh | awk 'NR==2 {print; exit}'`
echo 3 is `sh test.sh | awk 'NR==3 {print; exit}'`
;;
esac

Explain:
execute command " sh ssh-login.sh 1", you can ssh access the first server, and type password.
execute command " sh ssh-login.sh 2", you can ssh access the second server, and type password.
execute command " sh ssh-login.sh list", you can list all of the servers.


阅读(1095) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~