SPUG: Quoting Question
Jon Burdge
jlb at io.com
Mon Oct 16 17:30:02 PDT 2006
I'm not totally clear on what you're using for the module, so it's sort of
hard to answer. You're right though that echo is probably not the right
choice.
There should be some way to open up a program on the remote host and write
to the programs STDIN. On the commandline, it would be something like
this:
cat outfile.txt | ssh user at host 'cat > outfile.txt'
How are you reading the file in the first place? I expect it might be
somewhat similar.
Bill is right, though, that you need to be careful about writing partial
files and so on. If you are constrained to this method, using a
temporary file then moving it into place over the target filename is
usually a safe method.
j
On Mon, 16 Oct 2006, Asa Martin wrote:
> Hi everyone,
>
> Long-time lurker, infrequent poster, but I have this really annoying quoting
> question. I'm writing a remote SSH script (but not using Net::SSH so any
> solution can't utilize any special Net::SSH stuff). I log into a remote
> system using ssh, read a file from the remote system into memory, parse
> through it line by line, and on certain lines make substitutions. Then I
> need to write the new file to the system. I am trying to send the changed
> stuff to the new file using the echo command, but it's not working very
> well.
>
> For example:
>
> for my $line (@array_of_lines)
> if ($line =~ /com2sec\s+.*$stuff_to_match/) {
> $line =~ s/$stuff_to_match/$new_stuff/;
> }
> $ssh->send('echo "$line"'); # this expands stuff I don't want it to!
> }
>
> $stuff_to_match and $new_stuff contain special characters, like quotes, $,
> @, etc. that I don't want expanded in the regular expression. And $line
> contains tabs, quotations, special characters, including # signs and $
> signs, etc. I'll want the white space and quotes to come across correctly,
> but any variable names that might be in $line I don't want expanded.
>
> Any help would be appreciated.
>
> Thanks,
>
> Asa
>
> P.S. The remote system is a Linux-type box (F5 Load Balancer) so I have the
> full set of Linux tools available if something better than echo would work.
> The problem is that I have only that one send() routine of some unknown SSH
> module.
>
More information about the spug-list
mailing list