Chinaunix首页 | 论坛 | 博客
  • 博客访问: 346424
  • 博文数量: 167
  • 博客积分: 2867
  • 博客等级: 少校
  • 技术积分: 1306
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-12 00:08
文章分类

全部博文(167)

文章存档

2017年(10)

2016年(5)

2015年(9)

2014年(10)

2013年(5)

2012年(17)

2011年(110)

2010年(1)

我的朋友

分类: LINUX

2011-05-09 15:18:23

一:使用expect 处理调用fdisk 
#!/usr/bin/expect -f
   spawn fdisk /dev/hda
   expect -exact "Command (m for help):"
   send -- "p\r"
   expect -exact "Command (m for help):"
   send -- "q\r"
   expect eof

二:使用expect进行ssh登录
#!/usr/bin/expect -f

set mypassword 21vianet
set target bbbb.txt
set timeout 10
spawn ssh root@211.99.208.49
expect "Password:"
set timeout 10
send "$mypassword\n"
expect "linux-nlx:~ #"
send "mkdir $target\n"
expect "*#"

需要注意的是,expect后面的书写,应该实际把命令执行一遍,看看会prompt出来什么字符串,然后写在expect后面。
这个东西非常好用:
spawn 启动一个进程来执行目标命令
expect:期望命令执行后会给出的字符串
send:给启动进程发送期望的值

===========================================================
shell 
<
阅读(737) | 评论(0) | 转发(0) |
0

上一篇:vi 替换

下一篇:about expect

给主人留下些什么吧!~~