Tip: Send device logfile to dropbox with one command

You can retrieve logs from the device in different ways, but usually to retrieve the full log, you will need to SSH to the device, move some files around and then use SCP to retrieve the file.

A much faster way is to push the logfile directly to your own dropbox, with a single command.

To do this, you will need to do the following.

  1. Create a Dropbox app by going here and input like so:
    https://www.dropbox.com/developers/apps/create

01

  1. Now click the “Generate” button under Generated access token

  2. You can now use the below commands to send files to your new dropbox folder located in “dropbox/Apps/AutoPi Logfiles”. Execute them in the web terminal, or in the ssh terminal by removing the cmd.run and quotes.

NOTE Remember to replace the YOUR_ACCESS_TOKEN with the actual token you received in the last step.

cmd.run 'gzip --keep -f /var/log/salt/minion'

And then run the following command to upload the data:

cmd.run 'curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer YOUR_ACCESS_TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"/minion.gz\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary @/var/log/salt/minion.gz'

NOTE: If the above command does not work, you can try this one instead
Same command in a single line, without the slashes

cmd.run 'curl -X POST https://content.dropboxapi.com/2/files/upload --header "Authorization: Bearer YOUR_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"path\": \"/minion.gz\"}" --header "Content-Type: application/octet-stream" --data-binary @/var/log/salt/minion.gz'
  1. You should now be able to see the uploaded file in your dropbox folder.

Best regards
/Malte

3 Likes

What about:
https://developers.google.com/drive/api/v3/manage-uploads
???

If the API provides a way to receive a file from a post request, then it should work exactly the same.
But the authentication might be different if you are using another API.

Copy/paste the last chunk of codes give me error when executing in the web terminal, I suspect copy from this forum is messing up the code with hidden characters etc. Unfortunately i know to little Linux to tell what is wrong. Anyway, this is the error i get.

image

1 Like

Hi @Andreas_Nygren

I changed the command slightly earlier today, by adding newlines to make it more readable, but I think i might have introduced a (few) typos…

I have updated the command above, can you try again?

Best regards
/Malte

Thank you Malte. Worked just fine now. :slight_smile:

1 Like

hello! I have some errors:
" % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:–:--

–:--:-- --:–:-- 0\r 0 4692k 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0\r 13 4692k 0 0 13 624k 0 406k 0:00:11 0:00:01 0:00:10 407k\r 33 4692k 0 0 33 1584k

  0   626k  0:00:07  0:00:02  0:00:05  627k\r 62 4692k    0     0   62 2912k      0   827k  0:00:05  0:00:03  0:00:02  827k\r 90 4692k    0     0   90 4256k      0   940k  0:00:04  0:00:04 --:--:--  940k\r100 4692

k 0 90 100 4692k 18 941k 0:00:04 0:00:04 --:–:-- 1058k\nError in call to API function “files/upload”: The given OAuth 2 access token is malformed.curl: (3) Illegal characters found in URL\ncurl: (3)

Illegal characters found in URL\ncurl: (3) Illegal characters found in URL\ncurl: (3) Illegal characters found in URL"

sorry … I’m not understanding anything anymore …

I copied the code and put my token

but I always get errors
Annotazione%202019-07-01%20130830

Hi Toch

Can you try removing the backslashes and the newlines \ on each line, so that it looks like this instead

cmd.run 'curl -X POST https://content.dropboxapi.com/2/files/upload --header "Authorization: Bearer YOUR_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"path\": \"/minion.gz\"}" --header "Content-Type: application/octet-stream" --data-binary @/var/log/salt/minion.gz'

(remember to replace the token again)

Best regards
/Malte

I tried, unfortunately it doesn’t work …