From 9f7f09d0f7d37d0927c43b2143c8dff0d1abd28b Mon Sep 17 00:00:00 2001 From: lissav Date: Thu, 19 Sep 2013 10:52:57 -0400 Subject: [PATCH] defect 3580 --- xCAT-client/bin/pscp | 1 - xCAT-client/bin/psh | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/xCAT-client/bin/pscp b/xCAT-client/bin/pscp index 0b57a6935..da7f0978e 100755 --- a/xCAT-client/bin/pscp +++ b/xCAT-client/bin/pscp @@ -12,7 +12,6 @@ $XML::Simple::PREFERRED_PARSER='XML::Parser'; use IO::Handle; use IO::Select; use Thread qw(yield); -use xCAT::Utils; use Getopt::Long qw(:config pass_through require_order); use POSIX qw(:signal_h :errno_h :sys_wait_h); my $interface; diff --git a/xCAT-client/bin/psh b/xCAT-client/bin/psh index c25951266..e93c2126a 100755 --- a/xCAT-client/bin/psh +++ b/xCAT-client/bin/psh @@ -14,7 +14,6 @@ $XML::Simple::PREFERRED_PARSER='XML::Parser'; #use Data::Dumper; use IO::Handle; use IO::Select; -use xCAT::Utils; use Getopt::Long; use POSIX qw(:signal_h :errno_h :sys_wait_h); use Thread qw(yield); @@ -192,11 +191,39 @@ sub sshnode { if (length($username)) { $username = "-l $username"; } my $in; my $args = join(" ",@_); - #print "ssh -o BatchMode=yes $username $node " . xCAT::Utils->quote($args) . " 2>&1 |\n"; - my $pid = open($out,"ssh -o BatchMode=yes $username $node " . xCAT::Utils->quote($args) . " 2>&1 |"); + #print "ssh -o BatchMode=yes $username $node " . "e($args) . " 2>&1 |\n"; + my $pid = open($out,"ssh -o BatchMode=yes $username $node " . "e($args) . " 2>&1 |"); $inputs->add($out); $nodehdl->{$out} = $node; $pids{$pid} = $node; } +sub quote +{ + my $str = shift; + + # if the value has imbedded double quotes, use single quotes. If it also has + # single quotes, escape the double quotes. + if (!($str =~ /\"/)) # no embedded double quotes + { + $str =~ s/\$/\\\$/sg; # escape the dollar signs + $str =~ s/\`/\\\`/sg; + $str = qq("$str"); + } + elsif (!($str =~ /\'/)) + { + $str = qq('$str'); + } # no embedded single quotes + else # has both embedded double and single quotes + { + + # Escape the double quotes. (Escaping single quotes does not seem to work + # in the shells.) + $str =~ s/\"/\\\"/sg; #" this comment helps formating + $str =~ s/\$/\\\$/sg; # escape the dollar signs + $str =~ s/\`/\\\`/sg; + $str = qq("$str"); + } +} + # vim: set et ts=2 sts=2 sw=2 :