Expect是一个免费的编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预。
#!/bin/sh
# Date: 2012/5/9
# Author: zhangkai
# Description: This script is used to bakup and scp resource package to remote machine.
# History:
passwd="123456"
date=`date +'%Y%m%d'`
expect -c "
set timeout -1
spawn bash -c \"scp -r root@10.20.189.194:/root/resource/log/* /data/package_bak/$date/logs/10.20.189.194/\"
expect {
\"(yes/no)?\" {
send \"yes\r\"
expect \"password:\"
send \"${passwd}\r\"
}
\"password:\" {
send \"${passwd}\r\"
}
}
expect eof
"
#!/bin/bash
server="10.20.189.194/7002"
user="escadmin"
password="123123"
expect -c "
set timeout -1
spawn bash -c \"python -O /opt/apps/noe/_frametest/testdeploy.pyo\"
expect \"server(ksyun.com/7002):\"
send \"${server}\r\"
expect \"user(escadmin):\"
send \"${user}\r\"
expect \"password:\"
send \"${password}\r\"
expect eof
"