Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152712
  • 博文数量: 42
  • 博客积分: 852
  • 博客等级: 准尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-10 09:59
文章分类

全部博文(42)

文章存档

2015年(2)

2013年(9)

2012年(21)

2011年(4)

2009年(6)

我的朋友

分类: LINUX

2009-07-24 15:47:29

#! /bin/bash
sh-cmd1
....
sh-cmdn
##################
expect <<\EOF
expect-cmd1
.......
expect-cmdn
EOF
##################
sh-cmdo
.......
sh-cmdp
##################
expect <<\EOF
expect-cmdr
.......
expect-cmds
EOF
##################

................
 
例:
[root@rhvm1 expect]# cat sshcmd2.sh
#!/bin/bash
#. ./timeout.sh
cat /dev/null > ./sshresult.txt
for name in $1
 do
  echo "[$name] machine's info:" | tee -a ./sshresult.txt
  echo""   | tee -a ./sshresult.txt
user=$2
passwd=$3
cmd=$4
expect <set timeout 10
#set host [lindex $argv 0]
#set user [lindex $argv 1]
#set  passwd [lindex $argv 2]
#set cmd [lindex $argv 3]
spawn ssh "$cmd"
expect {
    "*no" { send "yes\r";exp_continue }
    "*assword:*" { send "$passwd\n" }
    }
expect eof
EOF
  echo ""   | tee -a ./sshresult.txt
  echo ""   | tee -a ./sshresult.txt
  echo --------------------------------------------------------------------------  | tee -a ./sshresult.txt
 done
[root@rhvm1 expect]#
 
阅读(1123) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~