On Sat, 7 Dec 2002 10:57:31 -0900, [EMAIL PROTECTED] (Mark-Nathaniel
Weisman) wrote:

>> Hey all,
>>   I've got the script below that does not work, will anyone please tell me what 
>I've done wrong? I can't see where the script is failing and the logs simply say that 
>the script header is bad. I don't understand. Can someone please help?
>> 
>> ##!/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 greater than marks of course. Where am I going wrong? Help please?
>> Sample of machines.txt
>> >192.168.x.1,mary,password




>> I'm trying to capture the data from the uptime command into a file that is erased 
>every time the script is run.
Even if you get the script to run, it won't do what you want. Did you
write this or are you trying to adapt a different script to do what you
want?

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);
};

You dont need to open OUTFILE twice, to overwrite the
old file, and putting single quotes around something makes
it print literally. Also you are not going to get ssh to work
the way you have it, unless you are intending it for something
later.

Try something like this:

open (OUTFILE, ">records.txt")
                     or die "Error opening records.txt.$!,stopped";
my $uptime = `uptime`;
print OUTFILE  "$user  $host   $uptime";
close(OUTFILE);
};











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

Reply via email to