Choose login SSH using shell scripting custom implementation

Source: Internet
Author: User

Create two scripts in the system bin directory, respectively, Pssh tssh

Pssh

#!/usr/bin/expect-fSet IP [lindex$argv 0]set Port [lindex$argv 1]set Password [lindex$argv 2]set TimeoutTenspawn ssh [email protected]$ip-P$portExpect {"*yes/no"{Send "yes\r"; Exp_continue}"*password:"{Send "$password \ r"}}interact

Tssh

#!/bin/shEcho"here is a list of all your servers"Echo"1.A Server 192.168.100.11"Echo"2.B Server 192.168.100.12"Echo"3.C Server 192.168.100.13"Echo"0. Temporarily do not want to log in"Echo"Please enter the corresponding number, select the server you want to log in: \c"Readinputtest$input=0 Case$inputinch1) Pssh192.168.100.11  A 123456;;2) Pssh192.168.100.12  Aadmin;;3) Pssh192.168.100.13  Aroot;; Esac

Remember to add executable permissions to the script

Then execute TSSH on the terminal and the following results appear

Here is a list of all your servers
1.A Server 192.168.100.11
2.B Server 192.168.100.12
3.C Server 192.168.100.13
0. Temporarily do not want to log in
Please enter the corresponding number, select the server you want to log in: 1
Spawn ssh [email protected]-p22
CentOS Release 6.8 (Final)
Kernel \ r on an \m
[email protected] ' s password:
Last Login:thu 18:34:58 from 192.168.100.2

Welcome to Aliyun Elastic Compute service!

[Email protected] ~]#

Choose login SSH using shell scripting custom implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.