Bash / ssh / scp quoting problem...
Robert Heller
heller at deepsoft.com
Thu Feb 11 18:25:40 UTC 2021
At Thu, 11 Feb 2021 18:15:47 +0000 "Ubuntu user technical support, not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:
>
> Content-Type: text/plain
>
> On Thu, Feb 11, 2021 at 06:04:28PM +0000, Colin Watson wrote:
> > On Thu, Feb 11, 2021 at 09:23:04AM -0500, Robert Heller wrote:
> > > I have a script to convert document files. I have the conversion software on
> > > one machine but sometimes have the files on another. Sometimes the filenames
> > > have pesky shell meta characters (dreaded spaces -- thank you Steve Jobs).
> > >
> > > I have a bash script that uses scp and ssh to do the work:
> > >
> > > #!/bin/bash -v
> > > scp "$1" sauron:/extra/
> > > base=`basename "$1"`
> > > broot=`basename "$base" .doc`
> > > if [ "$broot" = "$base" ]; then
> > > broot=`basename "$base" .docx`
> > > fi
> > > ssh -X -Y sauron /usr/bin/doc2pdf -v "\"/extra/$base\""
> > > f1="/extra/${broot}"
> > > ssh sauron ls -l "\"$f1\".*"
> > > scp sauron:"\"$f1\".pdf" /scratch/
> > >
> > > The problem is the last line. I cannot figure out how to quote it properly.
> >
> > This is all relatively awful because *gestures wildly at history of scp
> > and shells*. Consider using sftp or rsync instead of scp if you can.
> > Failing that, what you have should work if you add the -T option to scp
> > (which disables some checking on what the remote host is sending over
> > the scp protocol, implying a somewhat higher level of trust in the
> > remote host not to send certain kinds of maliciously-constructed file
> > names).
> >
> I second that advice, use rsync if you possibly can, it can handle
> files with awkward names much better than scp.
It just seems odd to use rsync with a single file...
>
--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller at deepsoft.com -- Webhosting Services
More information about the ubuntu-users
mailing list