DiffZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've created a script whitch executes some commands on remote 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

Replies are listed 'Best First'.
Re: Problem with perl expect
by jbrugger (Parson) on Feb 15, 2005 at 09:14 UTC
    Hi DiffZ, Please put youd example code between <code> tags, this makes it more readable.
    Have a look at the Writeup Formatting Tips for more info.
      Indeed adding <code> makes it a bit nicer to read :)