expect实现scp自动密码远程拷贝
时间:2010-07-20 来源:ITmaidou
#!/bin/bash
DATA_T=`date "+%Y%m%d" --date="0 days ago"`
DATA_Y=`date "+%Y%m%d" --date="1 days ago"` DIR_SRC=
FNAME_SRC= HOST_SRC=
USER_SRC=
PASSWD_SRC=="passwd@#\\\$2wd\r" CP_FROM_SRC="/usr/bin/scp -r $USER_SRC@$HOST_SRC:$DIR_SRC/$FNAME_SRC ."
#echo $CP_FROM_SRC expect -c "
set timeout 3000;
spawn $CP_FROM_SRC
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send $PASSWD_SRC;}
}
expect eof;"
DATA_Y=`date "+%Y%m%d" --date="1 days ago"` DIR_SRC=
FNAME_SRC= HOST_SRC=
USER_SRC=
PASSWD_SRC=="passwd@#\\\$2wd\r" CP_FROM_SRC="/usr/bin/scp -r $USER_SRC@$HOST_SRC:$DIR_SRC/$FNAME_SRC ."
#echo $CP_FROM_SRC expect -c "
set timeout 3000;
spawn $CP_FROM_SRC
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send $PASSWD_SRC;}
}
expect eof;"
相关阅读 更多 +