Linux shell and linuxshell

Source: Internet
Author: User

[Switch] linux shell and linuxshell

1. Before using keep CT, install two rpm packages first, download: http://download.csdn.net/detail/wang7dao/4416172
# Rpm-ihv expect-5.43.0-8.el5.i386.rpm
# Rpm-ihv expect-devel-5.43.0-8.el5.i386.rpm


2. Use an example of a script file to automatically lose the password
#! /Usr/bin/CT-f
Set password 123456
# Download
Spawn scp root@192.168.1.218:/root/a. wmv/home/yangyz/
Set timeout 300
Your CT "root@192.168.1.218's password :"
Set timeout 300
Send "$ password \ r"
Set timeout 300
Send "exit \ r"
CT eof


3. The example of embedding a trusted ct in the sh script -- jump to an intranet server by connecting to a public network server, and use the script directly without a password. /goto. sh servername
#! /Bin/bash
Passmsmallq10 = ""
Passzhsh = ""
Passfcwr = "B"
Passwapfx = "c"
Passadfx = "d"


Ip1 = "200.100.10.10"
Ip2 = "10.100.100.70"
Ip3 = "10.100.100.60"
Ip4 = "10.100.100.10"
Ip5 = "10.100.100.20"


Case $1 in
"Zhsh") passstr = $ passzhsh ipstr = $ ip2 ;;
"Fcwr") passstr = $ passfcwr ipstr = $ ip3 ;;
"Wapfx") passstr = $ passwapfx ipstr = $ ip4 ;;
"Adfx") passstr = $ passadfx ipstr = $ ip5 ;;
*) Echo "The parameter $1 isn' t exist"
Exit 0 ;;
Esac


Command1 = "ssh-l m_smallq-p 36000 $ ip1"
Command2 = "ssh-l mqq-p 36000 $ ipstr"


CT-c"
Set timeout 60;
Spawn $ command1;
CT {
\ "221.130.15.10's password: \" {send \ "$ passmsmallq10 \ r \"; exp_continue}
\ "M_smallq \" {send \ "$ command2 \ r \"; exp_continue}
\ "Mqq's password: \" {send \ "$ passstr \ r \"; interact}
}
"


Explanation of CT in the above example
CT-c "..." -- enter the command
Repeated CT {...} -- multiple rows of records in the record, from top to bottom scan matching, who matches who first processes.


4. Execute df-h on another machine through ssh and exit. The key point is that the command can be followed by multiple sending commands, and multiple commands can be distributed through \ r.
#! /Bin/bash
Ip1 = "183.62.178.191"
Command1 = "ssh-l root-p 14322 $ ip1"


CT-c"
Spawn $ command1;
CT {
\ "183.62.178.191's password: \" {send \ "aa \ r \"; exp_continue}
\ "Root @ \" {send \ "df-h \ r exit \ r \"; exp_continue}
}

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.