LoginSignup
18
16

More than 5 years have passed since last update.

scpを使ったシェルを作る

Posted at

scpはオプションでパスワードを入力することができないのでexpectを使ってパスワードを入力させる。

expectをインストールする

sudo yum install expect

scpを実行するシェルを作成する

unixscp.sh
HOST=ホスト名
USER=ユーザー名
PASS=パスワード
TARGET_FILE=転送するファイル
TARGET_DIR=転送先のディレクトリ

expect -c "
spawn scp ${TARGET_FILE} ${USER}@${HOST}:${TARGET_DIR}
expect {
\"Are you sure you want to continue connecting (yes/no)? \" {
send \"yes\r\"
expect \"password:\"
send \"${PASS}\r\"
} \"password:\" {
send \"${PASS}\r\"
}
}
interact
"

以上。
このやり方はあまり推奨されていない。
基本的にはsshの鍵を使うべきであろう。

18
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16