Last active
February 28, 2017 03:53
-
-
Save kenzo0107/a2f7525b6e201daa632c4dec36a9a1ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# remote serverへ転送するローカルファイル. | |
LOCAL_FILE="/tmp/*.csv" | |
# remote server 情報. | |
REMOTE_IP="**.**.**.**" | |
REMOTE_USER="user" | |
REMOTE_PASS="password" | |
REMOTE_PATH="/path/to/application/" | |
# sftpでファイルアップロード. | |
function sftpUpload() { | |
# /tmp/*.csv を ${REMOTE_PATH} へアップロードする | |
cat <<EOF > sftp.bat | |
cd ${REMOTE_PATH} | |
put ${LOCAL_FILE} | |
quit | |
EOF | |
# sftpでファイルアップロード. | |
function sftpUpload() { | |
expect -c " | |
set timeout 10 | |
spawn sftp -o \"batchmode no\" -b sftp.bat ${REMOTE_USER}@${REMOTE_IP} | |
expect { | |
\" Are you sure you want to continue connecting (yes/no)? \" { | |
send \"yse\r\" | |
expect \"password:\" | |
send \"${REMOTE_PASS}\r\" | |
} \"password:\" { | |
send \"${REMOTE_PASS}\r\" | |
} | |
} | |
interact | |
" | |
} | |
# sftpによるファイル転送実行. | |
sftpUpload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment