无交互shell脚本上传文件至服务器#!/bin/bash
CUR_DIR=`pwd`
PKT_DIR="$CUR_DIR"
REMOTE_USER=$remote_user
REMOTE_HOST=$remote_host
REMOTE_PASS=$remote_pass
expect <
spawn sftp $REMOTE_USER@$REMOTE_HOST
expect {
"Are you sure you want to continue connecting (yes/no)?"
{
send "yes\r" expect "password:" send "$REMOTE_PASS\r"
}
"password:"
{
send "$REMOTE_PASS\r"
}
}
expect ">" {
send "cd /opt\r"
send "put $PKT_DIR/*\r"
send "put ./tar.sh\r"
}
expect "*"
send "exit\r"
expect eof
END2