shell嵌套expect执行命令

wangshaoM00 2015-05-19

一直都想把expect的操作写到bash脚本里,这样就不用我再写两个脚本来执行了,搞了一下午终于有点小成就,给大家看看吧.

  系统:centos 5.x

1.先安装expect

yum -y install expect

2.脚本内容:

cat auto_svn.sh

#!/bin/bash
	passwd='123456'
	/usr/bin/expect <<-EOF
	set time 30
	spawn ssh -p18330 [email protected]
	expect {
	"*yes/no" { send "yes\r"; exp_continue }
	"*password:" { send "$passwd\r" }
	}
	expect "*#"
	send "cd /home/trunk\r"
	expect "*#"
	send "svn up\r"
	expect "*#"
	send "exit\r"
	interact
	expect eof
	EOF

相关推荐

ljbhander / 0评论 2011-05-07