Skip to content

Instantly share code, notes, and snippets.

@volpe28v
Created March 12, 2012 09:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volpe28v/2020932 to your computer and use it in GitHub Desktop.
Save volpe28v/2020932 to your computer and use it in GitHub Desktop.
scpを自動化するスクリプト
#!/bin/bash
HOST=対象ホスト名(IPアドレス)
USER=ログインユーザ
PASS=パスワード
TARGET_DIR=バックアップディレクトリ(ファイル)
BACKUP_DIR=保存先ディレクトリ
expect -c "
set timeout -1
spawn scp -Cpr ${TARGET_DIR} ${USER}@${HOST}:${BACKUP_DIR}
expect {
\" Are you sure you want to continue connecting (yes/no)? \" {
send \"yse\r\"
expect \"password:\"
send \"${PASS}\r\"
} \"password:\" {
send \"${PASS}\r\"
}
}
interact
"
@volpe28v
Copy link
Author

cron や jenkins で動作させる場合は、

interact

expect {"100%" { exit 0 }}

でいけた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment