Trouble with "|" when creating a variable using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with "|" when creating a variable using perl
# 1  
Old 03-20-2013
Trouble with "|" when creating a variable using perl

greetings,

not being much of a perl user i'm having an issue when trying to assign a value to a variable using the following:

Code:
$StatusRawString=`grep -F -e \'time...\' $Glstat | tail -n 1`;

when i execute the perl script i'm using the -w option to get some useful info on how the script is doing (or not doing) and i get the following output:

Code:
sh: -c: line 1: syntax error near unexpected token `|'
sh: -c: line 1: ` | tail -n 1'

it clearly doesn't like my syntax and and appears that it's executing the "| tail -n 1" on its own command line. i've tried dbl quotes and escapes and haven't found the magic combo. i am executing this perl script from a bash shell fyi. any suggestions?

thanx in advance.
# 2  
Old 03-20-2013
A few tips..

First, it's not perl that's not liking your syntax -- it's sh.

Which means that, yes, perl is running a new shell each and every time you use backticks.

So by embedding lots of shell code in backticks, you are running dozens of shells instead of one single one.

As for what's upsetting sh here... I'm guessing perl is shoving the string into sh inside single-quotes, which you are ending early with your own single quotes. Try unescaped double quotes.

Code:
$StatusRawString=`grep -F -e "time..." $Glstat | tail -n 1`;

# 3  
Old 03-20-2013
greetings,

i understand that it's the shell that dislikes what it's getting from the perl script. i just don't know how to get perl to give the shell what i'm obviously trying to pass to it. the escaped dbl quotes yielded the same result. if this helps, the line below works but i'm trying to eliminate the su and rsh and simply gettin what i need from the now nfs mounted filesystem where $Glstat lives:

Code:
$StatusRawString=`su $USER -c "rsh $HeadNode \\\"grep -F -e 'time...' $Glstat\\\" | tail -n 1"`;

# 4  
Old 03-20-2013
Have you tried using Perl's Grep function?

# 5  
Old 03-20-2013
Is $glstat a file or application?
# 6  
Old 03-21-2013
$Glstat is a large output file from a running process. unfortunately the line i'm looking for is in it many times, hence the need to tail -n 1 to grab the last occurrence of it. fyi, i managed to define the $Glstat variable as follows and got away with it:

Code:
$Glstat=`find $LsfTmp -name \"\*glstat\*\" | tail -n 1 2> /dev/null`;

thanks.

---------- Post updated 03-21-13 at 10:09 AM ---------- Previous update was 03-20-13 at 11:56 AM ----------

---------- Post updated at 10:10 AM ---------- Previous update was at 10:09 AM ----------

mystery solved!

i found out we had a perl developer here so i posed the question to him. he said that his first thought was that "$Glstat" had a newline. so he told me me drop the code below right after setting it:

Code:
chomp($Glstat);


Last edited by crimso; 03-20-2013 at 01:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Perl failure with "main::$fn" used only once:" in error logs

Hi all, Can anyone guess why this is happening? I am new to Perl, so please help me to fix this error: - I have a static html file which calls the cgi-perl script. HTML Code: <html> <head> <title> Hey Dude! </title> </head> <body> <form method="POST"... (3 Replies)
Discussion started by: bashily
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Creating a Shortcut (to just type "l" but it runs "ls -lah")

How do I create shortcuts? For example: I just want to type one key "l" and have it output the command of "ls -lah" I believe it's creating a file called l with 755 permissions but I'm not sure where to put the file. *if it matters, I'm on a shared hosting web server using cPanel with... (2 Replies)
Discussion started by: ijustsawmars
2 Replies

7. Shell Programming and Scripting

How perl releases "my" variable?

I have a question regarding to the following code: foreach my $Cnt ( @Cnts ) { my $abc = xyx->new(); do sth... aggregatedData->processData($abc); } my question is: whether perl will release the memory assign to "my $abc" each time after processData($abc) is being executed. ... (2 Replies)
Discussion started by: lilili07
2 Replies

8. Shell Programming and Scripting

if [ "variable" = "numerical-range" ]; then

been a while so i'm a bit rusty and need a little help. writing a script that needs to compare $EXECHOST(a number) against a numerical range and then set a value. below isn't working but should give you folks an idea of my goal: if ; then echo "This is a 32B machine, exiting..." if ;... (4 Replies)
Discussion started by: crimso
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question