【www.bbyears.com--CentOS】
系统:centos 6.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 root@192.168.10.22
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
这样写的话,就方便得很多,一个脚本就包括完了.
expect的简单用法及举例
使用脚本文件的例子--实现自动输密码
代码如下 #!/usr/bin/expect -fset password 123456
#download
spawn scp root@192.168.1.218:/root/a.wmv /home/yangyz/
set timeout 300
expect "root@192.168.1.218"s password:"
set timeout 300
send "$passwordr"
set timeout 300
send "exitr"
expect eof