[TriLUG] Perl. Help. Needed.

Greg Brown gwbrown1 at gmail.com
Wed Mar 11 15:30:56 EDT 2009


William:

Thanks for the prompt reply.  Originally I was using 'CONFIG' as a handle
but I was having tremendous difficulty simply printing the results of my
'show run' anywhere except (no pun) STDOUT.. which is why I started to mess
around with redirecting STDOUT.

I know I'm missing something very basic (no pun again) but darn it, I can't
see it in here.

Thanks!

Greg

On Wed, Mar 11, 2009 at 3:25 PM, William Sutton <william at trilug.org> wrote:

> Can I suggest that, instead of opening STDOUT and printing to that, that
> you open a different file handle, say, CONFIG, and write the lines you want
> to see there, and print them as well if you want to see them on your screen?
>  Also, if you're not doing it, I suggest using
>
> $|=1;
>
> to turn on autoflush.
>
>
> William Sutton
>
>
>
> On Wed, 11 Mar 2009, Greg Brown wrote:
>
>  I'm throwing my hands up in disgust.
>>
>> My Perl/Expect.pm script prints to STDOUT just like it should.
>>
>> I would like to redirect ONE PART OF THIS SCRIPT to a file from STDOUT
>>
>> Code snippet:
>>
>>       $ssh->expect(30,'(tcl)') || die "Never got the tcl prompt: $!\n";
>>
>>       open(STDOUT, ">./configs/$fileName") || die "can't write to
>> ./configs/$fileName: $!\n";
>>
>>       print STDOUT "screw this script!!!!!  I"M SICK OF IT!\n";
>>
>>       # now send the 'show run' comamnd
>>       print $ssh "exec \"show run\"\r";
>>
>>       print STDOUT "AGAIN!  screw this script!!!!!  I"M SICK OF IT!\n";
>>
>>       close (STDOUT);
>>
>> Now when I run the script my outfile file contains "screw this script!!!!!
>> I"M SICK OF IT!"  and the "AGAIN" line - and ONLY those lines.. not the
>> result of the command run by the expect module.  To make matters more
>> screwy
>> the results of 'show run' don't appear on the screen, i.e. they aren't
>> going
>> to STDOUT.  But they aren't going to the redirected file either.
>>
>> Why?
>>
>> I don't want to log the output of the entire script, just this one
>> command.
>> This should work.  If the results of my 'show run' aren't there when I
>> redirect STDOUT to a file and they are there when I don't where the hell
>> does it GO?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
>>
>> Beer please.
>> --
>> TriLUG mailing list        :
>> http://www.trilug.org/mailman/listinfo/trilug
>> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>>
>>  --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>



More information about the TriLUG mailing list