Thread: Help please

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

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Help please


    Hi all i'm newbye
    i need to do i little PERL script but i have not study PERL.
    i need it in my university thesys... someone can help me??

    this is my script but it's incomplete:

    #!/usr/bin/perl
    #use lib /root/.cpan/build;
    use Net::SSH::Perl;
    my $host="10.5.0.254";
    my $user="admin";
    my $pass="cisco";
    my $cmd="show spanning-tree summary | begin vlan";
    my $ssh = Net::SSH::Perl->new($host);
    $ssh->login($user, $pass);
    my($stdout, $stderr, $exit) = $ssh->cmd($cmd);


    i need the output is saved in a txt file. How i can do???


    thank u all for your help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    833
    Rep Power
    496
    Can't you just print it to a file?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Now i have
    Print $stdout

    But i need to save the output in a file before so i can add other comands such as GREP and AWK
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    833
    Rep Power
    496
    I do not see:

    Code:
    print $stdout;
    in your code in the first post.

    Where do you have it. Please post a more complete code snippet, at this point seem things seem to be missing.

    If you want to print to a file:
    1. first open the file

    Perl Code:
    my $outputfile = "result.txt";
    open my "$OUT_FH", ">", $outputfile or die "cound not open $outputfile $! \n"
    ;

    2. Then, whenever you want to print to the file:

    Perl Code:
    print $OUT_FH "whatever you want to print \n";


    3. Don't forget to close the file before you try to awk or grep it:

    Code:
    close $OUT_FH ;
  8. #5
  9. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,261
    Rep Power
    1810
    Since perl can perform all the functions of grep and awk without calling them, you would probably find it worthwhile to learn the language and do the whole job that way.

    Comments on this post

    • Laurent_R agrees

IMN logo majestic logo threadwatch logo seochat tools logo