why are you printing the comman to a file... this is how I would rewrite the
part that does the command. If you dont want to write it as a shell command
use Socket, or use IO::Socket.

use FileHandle;
use IPC::Open2;
My (@machines,$host,$user,$pass)

# read your record
Open(INFILE,"<machines.txt") || die "Error opening machines.txt.$!,stopped"
chomp ( @machines = <INFILE> );
Close(INFILE);

Foreach my $rec (@machines) {
    ($host,$user,$pass) = split(/,/, $rec);
    open2(*RD_HD, *WR_FH, "ssh $user\@$host uptime") || die cant fork a
child;
    <RD_FH>;

        if(   m/password/ ){
            print WR_FH "$pass\n";

        print "\t\t\tHOST $host responded with\n";
        print
"__________________________________________________________\n";
                 while (<RD_FH>){print};

        }
        else{
            print "error msg from ssh: $_\n";
        }



}
exit 0;

this code is untested for more info see perldoc perlipc


> # or die "Error opening records.txt.$!,stopped";
> # close(OUTFILE);
> # open (OUTFILE, ">>records.txt")
> # or die "Error opening records.txt.$!,stopped";
> # print OUTFILE 'ssh -l $user $host "uptime"';
> # close(OUTFILE);
> #};









> ##!/usr/bin/perl
>
> #My (@machines,$host,$user,$pass)
>
> #Open(INFILE,"<machines.txt")
> # or die "Error opening machines.txt.$!,stopped"
> #@machines = <INFILE>;
> #Close(INFILE);
> #Foreach my $rec (@machines) {
> # chomp($rec);
> # ($host,$user,$pass) = split(/,/, $rec);
> # open (OUTFILE, ">records.txt")
> # or die "Error opening records.txt.$!,stopped";
> # close(OUTFILE);
> # open (OUTFILE, ">>records.txt")
> # or die "Error opening records.txt.$!,stopped";
> # print OUTFILE 'ssh -l $user $host "uptime"';
> # close(OUTFILE);
> #};
> Without the hash marks of course. Where am I going wrong? Help please?
>
> His Faithful Servant,
> Mark-Nathaniel Weisman
> President / CEO
> Infinite Visions Educational Systems Inc.
> Anchorage, Alaska
> http://www.ivedsys.com
> [EMAIL PROTECTED]
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to