SPUG: Quoting Question

Asa Martin asa.martin at gmail.com
Mon Oct 16 17:02:03 PDT 2006

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

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.



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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20061016/2e0d8036/attachment.html 

More information about the spug-list mailing list