in reply to Re: Comparing localtime to a remote file's modification time.
in thread Comparing localtime to a remote file's modification time.

I'm using bourne for this... but escaping the single quotes like this: $FileTime = `ssh $ServerName \'perl -e \'(stat($FP_RemoteFile))[9];''`; or $FileTime = `ssh $ServerName \'perl -e \'(stat($FP_RemoteFile))[9];\'\'`; gives me the same syntax errors. (sh: syntax error at line 1: `(' unexpected) It looks as though the shell is actually complaining and, therefore, I guess I should assume that the perl one-liner format (quoting) is incorrect? In this, Ikegami, you may be on the right track. I'd love to put this in a script on the remote machine and run it from our watch server but then I'd need tiny scripts on every server that needs to be watched. This would make things a bit too complex to maintain. Is there no way to stat a remote file using ssh from within a perl script and capture the output?

Replies are listed 'Best First'.
Re^3: Comparing localtime to a remote file's modification time.
by ikegami (Patriarch) on Oct 23, 2006 at 21:03 UTC

    When Perl sees \' in a string literal, it places just ' in the string, so you haven't changed anything.

    You seem to have missed half of my comment.
    I didn't suggest that you escape the 1st and 2nd ' with \.
    I didn't suggest that you escape all the ' with \.
    I suggested that you escape the 2nd and 3rd ' with \\.

    $FileTime = `ssh $ServerName 'perl -e \\'(stat($FP_RemoteFile))[9];\\''`;
    executes
    ssh $ServerName 'perl -e \'(stat(...))[9];\''
    which executes
    perl -e '(stat(...))[9];'
    on the remote machine if sh behaves as I think it does.

    Update: stat($FP_RemoteFile) is also wrong. You need to convert the contents of $FP_RemoteFile into a Perl literal, then you must escape it for sh.

      You're right, of course (about both: my lack of reading comprehension and the explanation). I guess thinking it through should've worked for me. Thanks again.