in reply to Get remote file TimeStamp

You don't necessarily need Perl for that.

stat -c%Y somefile

should also output the modification time (in seconds since the epoch — if you want human readable form, use format %y instead).  Simply run the command via ssh (which I presume you are allowed to do).

Replies are listed 'Best First'.
Re^2: Get remote file TimeStamp
by Saved (Beadle) on Feb 28, 2012 at 18:17 UTC
    Excellent, works fine, I'll go with that. Thanx.
Re^2: Get remote file TimeStamp
by Saved (Beadle) on Feb 29, 2012 at 17:22 UTC

    This was fine on Linux/bash , but not HP-UX/ksh. I then got this working at the command line

    ssh -q aimuat perl -e \'\$MTIME = \( stat \( \"Envs_aimuat.xml\" \)\)\[9\]\;print \$MTIME\;\'

    But when I put in into a perl script it fails

    $TStamp=`ssh -v aimuat perl -e '\$MTIME = \( stat \( \"Envs_aimuat.xml +\" \)\)\[9\]\;print \$MTIME\;'`; print "$TStamp";
    Any Ideas? Thanx

      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`;

        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