[clug] A "How to" SSH question: copy file (scp/sftp) to remote system, then trigger a handler on remote.

Scott Ferguson scott.ferguson.clug at gmail.com
Thu Jan 21 06:15:12 UTC 2016



On 21/01/16 16:45, steve jenkin wrote:
> I’m looking to move files to a remote system with ssh and have the copy trigger something to deal with them.
> 
> scp “uses ssh for data transfer”, then sets owner/group, permissions & timestamp of the remote file.
> <https://en.wikipedia.org/wiki/Secure_copy>
> 
> It’s possible to code scp as an ssh command, like:
> 	ssh remote ‘cat >tmp;chmod user.group tmp;touch +hhmmss tmp;mv tmp destfile’ <srcfile

Sort of...

ssh steve at somewhere.there "scp steve at somewhere.else somestuff/ someplace
&& thendosomethingfunky.sh" (you could do better error handling in a
batch script)

thendosomethingfunky.sh can hold a function that does the processing per
file (date etc), inherited directory permissions should do the chmod for
you. (plus a simple sendmail command to provide you with a completion
report).

> 
> I’d like to trigger a command on the remote system to do something with the recently arrived file, i.e. “pick it up” and process it in some way.

use the ssh to call a batch file on the remote system?

> 
> In the above pseudo-code above:
> 	ssh remote ‘cat >tmp;chmod user.group tmp;touch +hhmmss tmp;mv tmp destfile;exec /path/to/command destfile&’ <srcfile
> 
> On some systems, I’ve implemented an ‘incoming’ directory with a background daemon that regularly scans the directory and process the files one by one if found, otherwise sleeps till next scan.
> 
> Not what I want to do here.
> 
> An alternative is to execute first the processing command and just pipe the data to it via STDIN, passing in a
> Problem with this is:
>  a) organising temp dir for large files, and
>  b) overloading receiving/processing host with too many simultaneous calls

use a WHILE instead of a FOR in the remote batch script?

> 
> Questions:
> 
> 1. has anyone seen this done? How?
>    There are going to be a lot of subtle errors and race-conditions, not the least, clashing filenames from simultaneous copies.
>     I’m not looking to rediscover them for myself. Life is too short :(
> 
> 2. Is there a standard/semi-std SSH sub-system on the server side to perform this copy/trigger function?
>     Even non-standard, like creating automatic triggers on specific file-system activity. [Is that a thing in modern linux’s?]
> 
> 3. For extra points, having delivered a file from my local system, I shouldn’t delete it before it’s saved & processed on the remote.
>      [in DB terms, a restartable transaction]
>    That implies either the sending SSH to hang around, waiting for a signal of some sort,
>      or some kind of return signal / file to be returned on next connection.
>    Also, I don’t ever want to get stuck in a loop of ‘send file, crash remote handler, resend file, crash remote, <till end of time>’
>    Seen that more than once :(
> 
> Thanks in Advance
> steve
> 
> --
> Steve Jenkin, IT Systems and Design 
> 0412 786 915 (+61 412 786 915)
> PO Box 48, Kippax ACT 2615, AUSTRALIA
> 
> mailto:sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin
> 
> 

-- 
    A: Because we read from top to bottom, left to right.
    Q: Why should I start my reply below the quoted text?

    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?

    A: The lost context.
    Q: What makes top-posted replies harder to read than bottom-posted?

    A: Yes.
    Q: Should I trim down the quoted part of an email to which I'm reply

http://www.idallen.com/topposting.html



More information about the linux mailing list