Expect command scripting language combat

Source: Internet
Author: User

I. Expect implement auto-fill password

1.VI ssh.exp.201

#!/usr/bin/expect

Spawn ssh-p 20000 [email protected]/sbin/ifconfig eth0
Set Timeout 60
Expect "*password:"
Send "abcdef\n"
Expect EOF
Exit


2.chmod ssh.exp.201 #注. If you do not have permission to execute, you can expect,700 permissions directly. Prevent other users from viewing passwords in scripts

3. Execution Effect:

./ssh.exp.201
Spawn ssh-p 20000 [email protected]/sbin/ifconfig eth0
[email protected] ' s password:
Eth0 Link encap:ethernet HWaddr 00:0c:29:31:2b:a0
inet addr:192.168.1.201 bcast:192.168.1.255 mask:255.255.255.0
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:2417 errors:0 dropped:0 overruns:0 frame:0
TX packets:2419 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:229270 (223.8 KiB) TX bytes:186485 (182.1 KiB)



650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4C/39/wKiom1Q53I2gUTofAAHJJrbJAJk672.jpg "title=" 1.png " alt= "Wkiom1q53i2gutofaahjjrbjajk672.jpg"/> Two. Expect syntax:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4C/39/wKiom1Q53smxC-TsAAM4w78gTts738.jpg "title=" 2.png " alt= "Wkiom1q53smxc-tsaam4w78gtts738.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4C/3F/wKioL1Q54XvDcqY7AALKBDCJFZY215.jpg "title=" 4.png " alt= "Wkiol1q54xvdcqy7aalkbdcjfzy215.jpg"/>


Exp_continue principle, when to prompt input, to match, when the match succeeds, re-enter the expect, a bit like for the continue in the loop, if there is no exp_continue, then the contents of the expect, only one input matches once, No matter how many keywords you have

Argument:

#!/usr/bin/expect

Spawn ssh-p 20000 [email protected].1.201/sbin/ifconfig eth0
Set Timeout 60
Expect {
-timeout 60
"Yes/no" {exp_send "yes\r"; Exp_continue}
"*password:" {exp_send "abcdef\r"}
Timeout {puts "Expect is time out"; Return
}

Expect EOF
Exit


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4C/3A/wKioL1Q53_HBlODaAAR-QmCVbOA152.jpg "title=" 3.png " alt= "Wkiol1q53_hblodaaar-qmcvboa152.jpg"/>

This article is from "Spider-Man" blog, please be sure to keep this source http://txidc.blog.51cto.com/9138217/1562807

Expect command scripting language combat

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.