Chinaunix首页 | 论坛 | 博客
  • 博客访问: 355425
  • 博文数量: 80
  • 博客积分: 2056
  • 博客等级: 大尉
  • 技术积分: 961
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-19 12:17
文章分类

全部博文(80)

文章存档

2011年(9)

2010年(13)

2009年(41)

2008年(17)

我的朋友

分类:

2010-07-16 17:44:00

1.
cat ssh.exp

#!/usr/bin/expect -f
set HOST [lindex $argv 0]
set PASS "your-password"
spawn ssh $HOST
set timeout 10
expect {
    "*(yes/no)*" { send "yes\r" }
    "*password*" { send "${PASS}\r" }
}
expect "*$"
send "mkdir /tmp/test\r"
send "exit\r"
interact

使用:
expect ssh.exp your-ip  或者 ./ssh.exp your-ip
作用:
登录 your-ip 后执行 mkdir /tmp/test 退出

2.
cat scp.exp

#!/usr/bin/expect -f
set CMD0 [lindex $argv 0]
set CMD1 [lindex $argv 1]
set PASS "your-password"
spawn scp -r $CMD0 $CMD1
set timeout 10
expect {
    "*(yes/no)*" { send "yes\r" }
    "*password*" { send "${PASS}\r" }
}
interact

使用:
expect scp.exp root@your-ip:/tmp/test /tmp
expect scp.exp /tmp/test root@your-ip:/tmp/
用途:
将your-ip /tmp/test 目录scp到本机 /tmp
将本机 /tmp/test 目录scp到 your-ip /tmp

阅读(1132) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~