-----Original Message----- From: hdan [mailto:[EMAIL PROTECTED] Sent: Thursday, April 22, 2004 2:14 PM To: Jayakumar Rajagopal Cc: hdan; [EMAIL PROTECTED] Subject: Re: backtick variable substitution
Yes, it works at a ksh prompt: harold$ cat -n app_system.log.7 | grep -E 'period' | cut -f 1 | while read x; do head -$x app_system.log.7 | tail -2 15-APR-2004 10:49:03 PI-I-PI_Log_Report_Period Report period 01/01 00:00 - 04/15 23:59. From time 1072933200 to 1082087940. 15-APR-2004 10:49:54 PI-I-PI_Log_Report_Period Report period 01/01 00:00 - 04/15 23:59. From time 1072933200 to 1082087940. 15-APR-2004 12:54:30 PI-I-PI_Log_Report_Period Report period 01/01 00:00 - 04/15 23:59. From time 1072933200 to 1082087940. 15-APR-2004 12:54:59 PI-I-PI_Log_Report_Period Report period 01/01 00:00 - 04/15 23:59. From time 1072933200 to 1082087940. 15-APR-2004 12:55:32 PI-I-PI_Log_Report_Period Report period 01/01 00:00 - 04/15 23:59. From time 1072933200 to 1082087940. When run from my perl script I get this because $x is null (I think): harold$ /home/harold/bin/search.pl Usage: head [-Count | -n Number | -c Number] [File...] Usage: head [-Count | -n Number | -c Number] [File...] Usage: head [-Count | -n Number | -c Number] [File...] Usage: head [-Count | -n Number | -c Number] [File...] Usage: head [-Count | -n Number | -c Number] [File...] Jayakumar Rajagopal wrote: Harold, (bottom posted) -----Original Message----- From: hdan [ mailto:[EMAIL PROTECTED] Sent: Thursday, April 22, 2004 1:54 PM To: Jayakumar Rajagopal Cc: hdan; [EMAIL PROTECTED] Subject: Re: backtick variable substitution Thanks. I've tried that, but it didn't work. I've also tried using exec and system instead of backticks. I tried using eval, too, although I wasn't sure where to put it in the statement. -harold Jayakumar Rajagopal wrote: Hi hdan, try \$ for $. I did not test it anyway. HTH, Jay -----Original Message----- From: hdan [ mailto:[EMAIL PROTECTED] Sent: Thursday, April 22, 2004 1:13 PM To: [EMAIL PROTECTED] Subject: backtick variable 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 -E '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 -E 'error' | cut -f 1 | while read x; do head -$x app_error.log | tail -2; done`; Thanks for any suggestions. [Jayakumar Rajagopal] +++++++++++++++++++++++ Please let me know if you can run whatever inside the backticks in shell ( unix prompt). Jay [Jayakumar Rajagopal] The same works well for me. It should work for you. You may try grep "-c -i" instead of "-E" . ( My machine does not support -E option ) . also try giving 'echo $x' just before 'head'. You will understand why the problem came. you must use \$x for $x, and -\$x for -$x.
