Expect example _shell script

Source: Internet
Author: User
Tags dname egrep

Compilation of exp Files

#!/usr/bin/expect
Set Timeout 10
Set fname [lindex $argv 0]
Set IP [lindex $argv 1]
Set dname [lindex $argv 2]
#spawn SCP $fname [email protected] $ip: $dname
Spawn ssh [email protected] $ip
Expect {
"*yes/no*" {send "yes\n"; Exp_continue}
"*password*" {send "aixocm\n"; Exp_continue}
}
Expect "*#*" {send "cd/tmp\n"}
Expect "*#*" {send "mkdir/tmp/zlj\n"}
Expect "*#" {send "exit\n"}
Expect EOF

Compilation of. sh files

#!/bin/bash
#
#nmap-N-st-p22 10.0.10.1-253|egrep-o ' 10.0.10. [0-9] {1,3} ' >ip.txt
#nmap-N-st-p22 10.0.10.1-253|egrep "22/tcp" |awk ' {print $} ' >statu.txt

Statu= (' Cat statu.txt ')

fname=/root/shell/7_1.sh
Dname=/tmp

Count=0
While read IP
Do
If ["${statu[$count]}" = = "Open"];then
./expect1.exp $fname $ip $dname
Fi
((count++))
Done < Ip.txt


If the. sh file is running, prompt spawn:command not found

Add x permission to the. sh file, run with the./x.sh style

This article is from the "Sunny Rain" blog, please be sure to keep this source http://8776055.blog.51cto.com/8766055/1837223

Expect example _shell script

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.