My Raspberry Pi3 Model B

Raspberry Pi で Dropbox にファイルをアップロードする Dropbox Uploader というスクリプトの設定に関する覚え書きです。

 

 

ダウンロード

まず GitHub から Dropbox Uploader をダウンロードします。

ここでは必要なスクリプトファイルだけダウンロードしてスクリプトを実行できるように実行権限を与えます。

andreafabrizi/Dropbox-Uploader: Dropbox Uploader is a BASH script which can be used to upload, download, list or delete files from Dropbox, an online file sharing, synchronization and backup service.

# Dropbox Uploader のダウンロード
$ curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh

# 実行権限付与
$ chmod +x dropbox_uploader.sh

# path の通ったディレクトリに移動
$ sudo mv dropbox_uploader.sh /usr/local/bin/dropbox_uploader

設定

スクリプト Dropbox Uploader を実行して初回の設定を行います。

Dropbox Uploader のウィザードに従って Dropbox のアクセストークンを Dropbox の公式ウェブから取得して登録します。

App Console – Dropbox

# Dropbox Uploader の実行
$ dropbox_uploader
 This is the first time you run this script, please follow the instructions:

 1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
 2) Click on "Create App", then select "Dropbox API app"
 3) Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
 4) Enter the "App Name" that you prefer (e.g. MyUploader101891203418496)

 Now, click on the "Create App" button.

 When your new App is successfully created, please click on the Generate button
 under the 'Generated access token' section, then copy and paste the new access token here:

 # Access token: ******************************************************************

 > The access token is ********************************************************************************. Looks ok? [y/N]: y
   The configuration has been saved.

使い方

Dropbox Uploader の使い方についてです。

アップロード

Dropbox Uploader で Dropbox にアップロードするには スクリプト名 upload ローカルファイルのパス Dropboxのパス で実行します。

# Dropbox/ にアップロード
$ dropbox_uploader upload test.txt /test.txt
 > Uploading "/home/hiyoshi/Documents/testmail.txt" to "/testmail.txt"... DONE

# Dropbox/inbox/ にアップロード
$ dropbox_uploader upload test.txt /inbox/
 > Uploading "/home/hiyoshi/Documents/testmail.txt" to "/inbox/testmail.txt"... DONE

cronで実行

Dropbox Uploader を cron などに登録して自動実行させる場合には -f オプションを使って Dropbox Uploader の設定ファイルを指定して実行します。

アクセストークンを保存した設定ファイルがユーザのホームディレクトリにあるので、 root ユーザなど別ユーザーで実行する場合には注意です。

$ sudo vim /etc/cron.daily/dropbox_uploader
#! /bin/sh
/usr/local/bin/dropbox_uploader -f /home/hiyoshi/.dropbox_uploader upload /tmp/logwatch_`date +%F`.txt /log/raspi/ >/dev/null

マニュアルを見ると Dropbox Uploader という名前のスクリプトですがダウンロードや削除などにも対応しているようです。

 

参考リンク

andreafabrizi/Dropbox-Uploader: Dropbox Uploader is a BASH script which can be used to upload, download, list or delete files from Dropbox, an online file sharing, synchronization and backup service.

【Raspberry Pi】Dropbox Uploader のインストール
Tagged on:     

コメントを残す