expect示例_shell脚本

发布时间:2020-09-19 13:07:05 作者:byzmkb
来源:网络 阅读:441

exp文件的编写

#!/usr/bin/expect
set timeout 10
set fname [lindex $argv 0]
set ip [lindex $argv 1]
set dname [lindex $argv 2]
#spawn scp $fname root@$ip:$dname
spawn ssh root@$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

.sh文件的编写

#!/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 $2}' >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


如果.sh文件运行时,提示 spawn:command not found

则给.sh文件添加x权限,使用./x.sh的样式运行

推荐阅读:
  1. CentOS安装expect
  2. expect 发送脚本

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

shell he ct

上一篇:SpringMVC Restful api接口实现的代码

下一篇:JS实现简单省市二级联动

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》