0

I am searching for a simple solution to send stdout (or a file content) from a linux host (raspi with bash) to my PC. The RaspberryPI has network/internet connection, but for security reasons it's not an option to set up SMB / FTP server on the raspi. It is anoying to send to an external FTP server all the time, using command line.

Please discuss general approaches (shell scripts for web form uploads, alternative options), and comment in particular on the scripting approach

I meanwhile tried to write a shell script...

#!/bin/bash
a='content='
b=`cat $2`
content=$a$b
curl -i -X POST https://cl1p.net/$1 -H "Content-Type: application/x-www-form-urlencoded" --data-binary "content=$content"

the script, as you see, should accept 2 command line args:

$1 ... clipboard "unique name"
$2 ... file to be sent to the clipboard)

When calling the script with the command line

$ ./sh ./bclip.sh 20171207testXX ./test.log

I expected to be able to download the content here: https://cl1p.net/20171207testXX

but when starting the script it says : not found.sh: 2: /boot/bclip.sh [... then the CURL upload output, and] (23) Failed writing body

What am I doing wrong?

Christoph Bimminger
  • 1,006
  • 7
  • 25
  • With the solution from https://stackoverflow.com/questions/6408904/send-post-request-with-data-specified-in-file-via-curl it should be possible to fill a web form... It seems an online clipboard such as https://cl1p.net/ could do the job for the file transfer (I am just writing a script doing so now...) please comment on this approach – Christoph Bimminger Dec 07 '17 at 15:15
  • 2
    Why don't you try and tell us later what fails ? SO explicitly forbids questions asking for books, tools or software libraries – Aserre Dec 07 '17 at 15:18
  • thank you for this remark. Didn't know that I am not allowed to ask for tool suggestions here, will consider that in future. But... is it allowed to discuss an approach, I mean I want to get better knowledge and want to know if there are existing (better) solutions than this self-made scripting, and such a question should be valid on SO, or not? – Christoph Bimminger Dec 07 '17 at 15:29

1 Answers1

1

Where'd you get the call to ./sh from? As the error says, there's no sh binary/script in your current location.You probably added that because you couldn't run your script directly?

Just remove the ./sh from the start and instead set the script as executable with chmod +x bclip.sh and call it with simply ./blicp.sh foo bar.log.

Copy the script to a location in you PATH env var (something like /usr/local/bin or ~/bin usually works) and you can call it without the path prefix ./

Olli K
  • 1,720
  • 1
  • 16
  • 17
  • sorry, typo in command line in the text. For sure, I did not try to use ./sh but just sh (otherwise there wouldn't have been any CURL upload output). But I followed your approach to install the script in /usr/local/bin, what makes user experience much better, for sure. Then I found out that my files were terminated with ^M (script was written on a windows machine) - didn't consider the CRLF encoding difference... removed the ^M with help from here https://stackoverflow.com/questions/29473520/removing-m-from-a-csv-file... but I still get the final error (23) Failed writing body... – Christoph Bimminger Dec 08 '17 at 09:12
  • Finally the reason for the (23) was that I added the "content=" via string concatenation, and again in the CURL call. Removed the content= from CURL line. The corrected script works now. – Christoph Bimminger Dec 08 '17 at 09:20
  • Glad I could be of help :) – Olli K Dec 08 '17 at 14:54