执行拷贝到远程服务器命令,然后执行部分命令;
set user "root"
set host "127.0.0.1"
set loginpass "root"
set cmd_prompt "]#|~]?"
expect -c "
spawn scp -r /usr/test/target/aaa-web/ ${user}@${host}:/usr/test/aaa-web/webapps
expect {
\"*assword\"
{
set timeout 300;
send \"${loginpass }\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
set timeout 1;
ssh ${user}@${host} -p 22 ;
expect {
yes /no { send \" yes \r\"; exp_continue }
*assword* { send \"${password}\r\" }
} ;
expect ${user}@${host} {send \" ls -l \r\" } ;
expect ${user}@${host} { send exit \r } ;
expect eof "