in reply to Re^2: Get remote file TimeStamp
in thread Get remote file TimeStamp

The backticks "eat" one level of escapes, when they occur literally within the backticks.  So, you either need to double escape them, or maybe better (to work around the ugliness), put the command in a variable, which you then interpolate into the backticks:

my $cmd = q|ssh -q aimuat perl -e \'\$MTIME = \( stat \( \"Envs_aimuat +.xml\" \)\)\[9\]\;print \$MTIME\;\'|; $TStamp = `$cmd`;

P.S., you can do away with the $MTIME variable if you use a "+" to syntactically disambiguate the argument to the print function:

my $cmd = q|ssh -q aimuat perl -e \'print +\( stat \( \"Envs_aimuat.xm +l\" \)\)\[9\]\;\'|; $TStamp = `$cmd`;

Replies are listed 'Best First'.
Re^4: Get remote file TimeStamp
by Saved (Beadle) on Mar 01, 2012 at 11:21 UTC

    This works well, and since I cannot add modules, it is preferred. My last problem which I am still working on is that the "aimuat" in the name argument of the ssh, and farther on in the file name needs to be a variable.

    foreach $SYSTEM (ifeuu1, ifcau1, ifcaa1, mifuat, aimuat, timeuat) { my $cmd = q|ssh -q $SYSTEM perl -e \'print +\( stat \( \"Envs_$SYSTEM. +xml\" \)\)\[9\]\;\'|; print `$cmd`; }

    Thanx for all your help, it is much appreciated

      There are several ways to solve this.  For one, you could use the interpolating qq operator (acts like double quotes), but then you'd have to double escape things...  Personally, I would rather use concatenation, which isn't pretty either, but somewhat easier to read (IMHO):

      foreach my $SYSTEM (qw(ifeuu1 ifcau1 ifcaa1 mifuat aimuat timeuat)) { my $cmd = 'ssh -q '.$SYSTEM.q| perl -e \'print +\( stat \( \"Envs_ +|.$SYSTEM.q|.xml\" \)\)\[9\]\;\'|; print `$cmd`; }

      Also note that I used qw() for the hostname list, because what you had were barewords, usage of which is generally discouraged.  qw(foo bar baz) is just a short form of saying 'foo', 'bar', 'baz'.

        Thank You. Having these alternatives in my toolbox is comforting, and useful. I tried putting a Place Holder SYSTEM in the cmd , and then doing a substitution. It seems to work also. Your help is valuable.

        foreach my $SYS (qw(ifeuu1 ifcau1 ifcaa1 mifuat aimuat timeuat)) { $cmd=q|ssh -q SYSTEM perl -e \'print +\( stat \( \"Envs_SYSTEM.xml\" \ +)\)\[9\]\;\'|; $cmd =~ s/SYSTEM/$SYS/g ; print "$SYS:" . `$cmd` . "\n"; }