in reply to Replacing backticks with system() and redirecting STDERR to file
my $command = 'ssh '. $node . ' "perl -e \'while (<>) { chomp; \$_ =~ /(.*)\\//; \`su xxx -c \"mkdir -p \$1\"\`; \`su xxx -c \"touch \$_\"\`;}\' 1>>$storageRootPath_log 2>>$storageRootPath_err"';The problem I see is that your variables are still in single quotes. Use double quotes and escape the embedded double quyotes, or rather, use qq() to properly interpolate the values. Something like (untested):
Note how you don't need to escape that much this way — but an embedded backslash needs to be doubled.my $command = 'ssh '. $node . qq( "perl -e 'while (<>) { chomp; /(.*)\ +\//; `su xxx -c \\"mkdir -p \$1\\"`; `su xxx -c \\"touch \$_\\"`;}' 1 +>>$storageRootPath_log 2>>$storageRootPath_err");
|
|---|