in reply to How to execute stat command in remote server

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!.

Replies are listed 'Best First'.
Re^2: How to execute stat command in remote server
by dpath2o (Acolyte) on Nov 26, 2013 at 05:13 UTC

    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

        Really? Here's my code and I get no return results with it, but if I remove ( -f $entry->{a} ) I get the files and the directories ... I guess I could add regex condition as well, but I'd rather not

        use Net::SFTP::Foreign; my $hostname='my.server.com'; my $sftp = Net::SFTP::Foreign->new( $hostname , user=>"me" ); my @files = $sftp->find( '/data/dir',wanted => sub{ my $now = time(); my $yesterday = $now-(24*3600); my (undef, $entry) = @_; ( ($entry->{a}->mtime < $now) and ($entry->{a}->mti +me > $yesterday) and (-f $entry->{a} ) ) } );