码迷,mamicode.com
首页 > 系统相关 > 详细

expect示例_shell脚本

时间:2016-08-12 22:05:57      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:shell

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的样式运行

本文出自 “天晴了要下雨” 博客,请务必保留此出处http://8776055.blog.51cto.com/8766055/1837223

expect示例_shell脚本

标签:shell

原文地址:http://8776055.blog.51cto.com/8766055/1837223

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!