the following is my script that i am working on- it fails to do
quite
the right thing.. qouting from one of the comments below::
"#skip_lines() is supposed to "skip" some lines of output.
#The problem is, that it DOESN'T even though the debug print statement
# "print "trash is $trash \n"; #debug " shows that it works-
#after leaving the for loop, it seems that CMD re-winds itself...
# i am flummuxed!!"
#!/usr/bin/perl
#
#
# Screen parser for Service Information System utilities
# on RAXP
# History::
# 5 feb 2004 skeleton and parse routines built (w/ test values.) wmw
#---------
use strict;
use diagnostics;
#----------
my $command = "/home/willy/Documents/conditional.testbed.exp";
my $pattern = "inittab";
my $skip;
$skip->[0] = 2;
$skip->[1] = 2;
my $table;
$table->{"PART"} = "INVENTORY";
#----------
# $pattern is only a string right now because i am assuming
# that the screens will be consistant with each call. $skip should produce
# enough flexibility for reuse.
open (CMD , "$command|") or die "Could not execute $command : $!";
parse_and_extract($pattern,$skip,$table);
close CMD;
#the following routine takes each line of the input (from a different
#program). When the pattern is matched, it calls get_inventory().
sub parse_and_extract {
my $pattern = shift; #what we look for.
my $skips = shift; #array ref. each value is # of lines to
skip
# over.
my $table = shift; #values are stored here. (hash reference)
while (<CMD>) {
get_inventory ($table,$skips) if ($_=~m/$pattern/);
print "parse_and_extract\n\r"; #debug
print "$_\n\r"; #debug
}
}
#the following routine assigns a key/value pair to a hash reference ($table)
#skip_lines() is supposed to "skip" some lines of output.
#The problem is, that it DOESN'T even though the debug print statement
# "print "trash is $trash \n"; #debug " shows that it works-
#after leaving the for loop, it seems that CMD re-winds itself...
# i am flummuxed!!
sub get_inventory {
my $table = shift;
my $skip = shift;
#$skip is an array reference for the case that several
#different screens will have to be parsed in the future-
#in which case, a flag will have to be added to determine
#which value in the array reference will be used.
# (perhaps $skip should be a hash of arrays?)
#first we skip the lines from the pattern match up to
#the line with the value we want.
skip_lines ($skip->[0]);
my $partnumber = $_;#check syntax-> is $_ instead?
#skip lines to the next value...
skip_lines ($skip->[1]);
my $inventory = $_;#check syntax-> is $_ instead?
$table->{$partnumber}=$inventory;
#print "keys:: "; #debug
#print keys(%$table); print "keys to the table\n"; #debug
#print " get_inventory() $_\n"; #debug
}
sub skip_lines {
my $lines = shift; #number of lines in file to skip over
print "in skip_lines() $_ before skip\n"; #debug
#<CMD> for 1..$lines; #not functioning...
for (0..$lines){
my $trash = <CMD>;
print "trash is $trash \n"; #debug
}
print "in skip_lines() $_ after skip\n"; #debug
}
#---------------------------------------
the following is the test expect script that i am using- as far
as i can tell, it's working fine :/ (there's extra stuff in there
since i was trying to learn how to use "if" statements earlier...)
#!/usr/bin/expect -f
#set ps $argv 0
set ps "password"
spawn telnet "localhost"
expect "ogin: "
send "willy\n"
expect "word:"
send "$ps\n"
expect "terminal:*"
send "ls\n"
#------------------
set file "Desktop.ini"
set counter 1
while {$counter < 5} {
send "echo $counter \n ls $file\n"
expect "No such file" {set counter [expr $counter + 1]}
expect "$file" {set counter 200}
sleep 2
}
send "ls\n\n"
sleep 2;
expect "terminal" {
if {$counter < 200} {
global subject
set subject "failed to produce report"
#expect "terminal:*"
send "w\n"
}
if {$counter > 100} {
#expect "terminal:*"
send "date\n"
}
}
expect "terminal"
send "cd /etc\n"
expect "terminal"
send "ls\n"
#------------------------------
interact
thanks,
willy
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>