centos6中shell嵌套expect执行命令

作者:袖梨 2022-06-30

系统: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 [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

这样写的话,就方便得很多,一个脚本就包括完了.

expect的简单用法及举例

使用脚本文件的例子--实现自动输密码

 代码如下 复制代码
#!/usr/bin/expect -f
set password 123456
#download
spawn scp [email protected]:/root/a.wmv /home/yangyz/
set timeout 300
expect "[email protected]'s password:"
set timeout 300
send "$passwordr"
set timeout 300
send "exitr"
expect eof

相关文章

精彩推荐