项目中有这么个需求 :后台通过上传文件到远程服务器不能手动填写密码,同时也要获取上传进度。
于是就想起了scp这个命令,下面是一组shell语句
shell.sh
expect -c "
set timeout 1200;
spawn /usr/bin/scp -r $1 $4@$2:$3
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$5\r\";}
}
expect eof;"
执行方式:sudo nohup script -q /dev/stdout -c "/home/idexadmin/shell.sh /home/admin/taskN.txt 203.156.255.159 /home/admin dmin K3YiiqmTfvzvo572grUV" >/tmp/nohup.out 2>err.log