1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SFTPをシェルで実行

Last updated at Posted at 2019-11-06

SFTPにID,PASSWORDでログインする場合
対話的なログインにsshpassを使います

例えば日時が最新のnginxのログファイルをSFTPを使ってアップロードする処理

sftp.sh
#!/usr/bin/sh

SFTP_HOST=hogehoge.domain
SFTP_ID=hogehoge
SFTP_PW=passw0rd

NEW_LOG_FILE=`ls -lt /var/log/nginx/access.log.* |head -n 1 |gawk '{print $9}'`

sshpass -p $SFTP_PW sftp ${SFTP_ID}@${SFTP_HOST} << EOF
put $NEW_LOG_FILE
bye
EOF

ログイン後SFTPの処理はEOFの間に記述します。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?