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) |