spawn激活一个scp的unix程序
spawn ssh 和spawn scp后都接一个expect,交互密码,这里不用再手动输入密码。没有expect输入密码过程,上传和复制都不会完成。
spawn ssh ${username}@${host}
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "${password}\r" }
}
expect "]#"
send "\[ ! -d /home/qappsom/jBossTempl \] && mkdir /home/qappsom/jBossTempl \r"
expect "]#"
send "\[ ! -d /home/qappsom/jBossTempl/${date} \] && mkdir /home/qappsom/jBossTempl/${date} \r"
expect "]#"
send "\[ ! -d /home/qappsom/jBossTempl/${date}/8080 \] && mkdir /home/qappsom/jBossTempl/${date}/8080 \r"
expect "eof"
spawn scp ${src_path}/${fileName} ${username}@${host}:/home/qappsom/jBossTempl/${date}/8080/${fileName}
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "${password}\r" }
}
expect "100%"
expect "eof"
spawn ssh ${username}@${host}
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "${password}\r" }
}
expect "100%"
send "cp /home/qappsom/jBossTempl/${date}/8080/${fileName} ${path8080}/${fileName} \r"
expect "eof"