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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.