LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 08-31-2010, 05:29 AM   #1
dontob
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Rep: Reputation: 0
Repeatedly getting command substitution: line 3: syntax error near unexpected token


Hello mates

I am repeatedly getting error:

command substitution: line 3: syntax error near unexpected token `('
command substitution: line 3: `ps -eo pmem,args | sort -k 1 -r | head -2 | sed '1d' | tee > ( awk {print'$2'}> new.txt) | cut -d'.' -f1'

I need to pass the value of `ps -eo pmem,args | sort -k 1 -r | head -2 | sed '1d' | tee > ( awk {print'$2'}> new.txt) | cut -d'.' -f1' to a variable mem.
I am using #!/bin/bash
This command works on shell without any issue.
Help required.....

Last edited by dontob; 08-31-2010 at 05:32 AM.
 
Old 08-31-2010, 07:00 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
There is just a dollar missing before the opening-parenthesis.

Yves.
 
Old 08-31-2010, 07:27 AM   #3
dontob
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Hello boss,

cpu.sh: line 4: $(awk {print'$2'} > new.txt): ambiguous redirect
 
Old 08-31-2010, 07:45 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

I cannot get your posted command to work at all. After A litle re-write I came up with this:

ps -eo pmem,args | sort -k 1 | sed '$d' | tail -1 | awk '{ pint $2 > "new.txt" } { printf("%.0f\n", $1) }'

This looks for the process that takes the most memory. The name is put in a file (new.txt) and the number is outputted to screen (all behind the . is removed).

I hope this does what you want.
 
Old 08-31-2010, 07:57 AM   #5
dontob
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Original Poster
Rep: Reputation: 0
But this command is not writing the output to new.txt.

ps -eo pmem,args | sort -k 1 | sed '$d' | tail -1 | awk '{ pint $2 > "new.txt" } { printf("%.0f\n", $1) }'

I need to the get the service taking memory write to a file and the mem usage to variable.

Thanks for your effort
 
Old 08-31-2010, 08:02 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

It does on my side:
Code:
$ cat new.txt
cat: new.txt: No such file or directory

$ VAR=$(ps -eo pmem,args | sort -k 1 | sed '$d' | tail -1 | awk '{ print $2 > "new.txt" } { printf("%.0f\n", $1) }')

$ echo $VAR
5

$ cat new.txt
/usr/bin/pan
Without knowing what you actually did it is hard to give pointers. Please provide the commands/code snippet that seems to fail.
 
Old 08-31-2010, 08:15 AM   #7
dontob
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for your valuable time.It worked.
 
Old 08-31-2010, 08:23 AM   #8
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 328

Rep: Reputation: 140Reputation: 140
When I executed the posted command in a bash terminal I got the same error message which you get when running the bash script.
The command started working when the space between '>' and '(' was removed.
 
Old 08-31-2010, 08:26 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Quote:
Originally Posted by dontob View Post
Thanks for your valuable time.It worked.
You're welcome

Please put the SOLVED tag on this thread (First post: Thread Tools pull down menu. Option is among them).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error near unexpected token jchmski Programming 5 06-18-2010 10:28 AM
./script.sh: line 2: syntax error near unexpected token `(' n00balert Programming 3 03-11-2010 04:22 PM
syntax error near unexpected token `then' snakernetb Linux - Server 4 02-16-2010 06:40 PM
syntax error near unexpected token `else' alex0 Programming 7 07-28-2009 08:01 AM
Syntax error near unexpected token fi Nortekman Linux - Newbie 8 02-27-2009 03:48 PM


All times are GMT -5. The time now is 08:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration