Advertisement

04.22.2004 at 03:02PM PDT, ID: 20964265
[x]
Attachment Details

backtick variable substitution

Asked by hmdan in Perl Programming Language

Tags: perl, variable, backtick, substitution

Hi all,

Hopefully someone can help me out with this one.

I have a perl script that runs rsh commands to monitor a remote server.  To minimize time and bandwidth I need to maximize the processing that is done on the remote server and minimize the number of rsh commands done.

My question is, how can I place a while loop within a system call so that the loop variable is substituted correctly?  Here is an example:


$THE_ERRORS =
`rsh remote_box "cat -n app_error.log | grep 'error' |
cut -f 1 | while read x; do head -\$x app_error.log | tail -2; done"`;

Basically, I'm trying to get the error message line and the line before it returned into $THE_ERRORS.  The problem is that $x is not being interpreted correctly by the head command.

For simplicity, we can take the whole rsh out of the picture and use this as an example:

$THE_ERRORS =
`cat -n app_error.log | grep 'error' |
cut -f 1 | while read x; do head -\$x app_error.log | tail -2; done`;


Thanks for any suggestions.Start Free Trial
[+][-]04.22.2004 at 04:00PM PDT, ID: 10894618

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2004 at 06:41PM PDT, ID: 10895498

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.22.2004 at 06:51PM PDT, ID: 10895558

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.23.2004 at 02:05AM PDT, ID: 10897479

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.23.2004 at 02:14AM PDT, ID: 10897520

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.23.2004 at 07:23AM PDT, ID: 10900063

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.23.2004 at 08:13AM PDT, ID: 10900572

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, variable, backtick, substitution
Sign Up Now!
Solution Provided By: stefan73
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.23.2004 at 09:02AM PDT, ID: 10901160

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32