#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Posts
    5
    Rep Power
    0

    Search Text File for String on Remote Computer


    I'm trying to figure out how I can search for any occurance of a specific string in a text file on a remote computer. My OS is redhat 5. The following is a way, but not so sure it's the best way:

    Code:
    my $rc = `ssh -q machineName "cat /tmp/file.txt" | grep TextToSearch`;
    if ($rc}
    {
      print "found your string";
    }
    else
    {
       print "no such string";
    }
    Any thoughts?

    Thanks,
    Eric
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    If it works, fine for you. After all, it is quite simple.

    But it is usually better and more powerfil to use specialized CPAN modules rather than system commands. Take a look at the
    Code:
    Net::SSH
    module.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,875
    Rep Power
    1225
    Another option would be File::Remote

IMN logo majestic logo threadwatch logo seochat tools logo