For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > February 2005 > Problem with per expect();









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with per expect();
DiffZ

2005-02-15, 4:50 am

Hi all,

Ive created a script whitch executes some commands on rome systems.
This worked well until I used a long command.

This is a part of the script:

$connection->send("$cmd\r");
if(length($cmd) > "25")
{
$cmd = substr($cmd, -20);
}
$connection->expect(8, '$cmd');
$connection->expect($timeout, $prompt);
$data = $connection->exp_before();
print "Command DATA: \n$data\n";

The problem is that when I execute a long command (more than one line) the terminal screws it up so i only see the last part of the command. To fix this I use substr to match only the last 20 chars of the command.

But somehow the perl Expect doesnt see the command because it will timeout.

The command it executes is:
cat /etc/testfile | awk '{ FS = ":" ; print $1 }' | grep -v '^[#*]' | grep -v '^$'

The output I get back (what actually is in $data) is:
":" ; print $1 }' | grep -v '^[#*]' | grep -v '^$' <
Command output 1
(... SNIP ...)
Command output xx

That first line contains a part of the command, and I dont want to see that line. I cant just cut of the first line because with simple commands it works fine...

I tried some stuff.. to escape the $ and # and stuff, use substr but nothing seems to work, does someone know a solution?

Thanks in advance,
DiffZ
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com