Bash / ssh / scp quoting problem...
Chris Green
cl at isbd.net
Thu Feb 11 18:15:47 UTC 2021
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.
--
Chris Green
More information about the ubuntu-users
mailing list