qsl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am having a remote server using telnet I connected that one and having some files in one directory,I want to get the stat of that files present in that directory by using stat command executing in remote server uisng telnet.But it is giving an error message.If i execute the same command in my local machine manually it is working fine.Please let me know where i am doing wrong?
Let me show my code here,
@logfiles = $telobj->cmd("find . -mtime 0 -print"); foreach $logfile (@logfiles) { @contents = $telnet->cmd("($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$siz +e, $atime,$mtime,$ctime,$blksize,$blocks) = stat($logfile)"); print"content=> @contents \n"; }
But I am getting the following error,
content=> ) ksh: syntax error: `=' unexpected
Let me know monks how i have to solve this issue,I need the mtime of that remote file in @content.
Thanks.

Replies are listed 'Best First'.
Re: How to execute stat command in remote server
by Tanktalus (Canon) on Jun 28, 2006 at 20:02 UTC

    Your telnet cmd is interacting with ksh, not perl, at the other end. So you need to tell it to run something. You could, for example, tell it to run:

    @contents = $telnet->cmd(qq(perl -e '$,=$/; print stat(shift)' $logfil +e));
    But if you only need mtime, you could tell the remote perl to just return that.
    @contents = $telnet->cmd(qq(perl -MFile::stat -e 'print stat(shift)->m +time()' $logfile));
    Hope that helps.

Re: How to execute stat command in remote server
by salva (Canon) on Jun 28, 2006 at 20:22 UTC
    if you can use ssh/sftp instead of telnet to access the remote server:
    use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new(host => $hostname) or die "unable to connect to $hostname"; my $t24h_ago = time - 24*3600; my @lf = $sftp->find('.', wanted => sub { my (undef, $entry) = @_; $entry->{a}->mtime > $t24h_ago; }); for my $lf (@logfiles) { my $name = $lf->{filename}; my $attr = $lf->{a}; printf("file: %s, mode: %o, uid: %d, gid: %d, size: %d, atime: %d, m +time: %d\n", $name, $a->mode, $a->uid, $a->gid, $a->size. $a->atime, $a->m +time); }
    though, you would need the development version of Net::SFTP::Foreign, available from CPAN but not installed by default by the CPAN module!.

      I found this useful. Thank you. I'm now trying to just extract the modified files *not* directories. Any insight I'd be grateful as

       (-f $entry->{a} )

      does not work.

        sure it does