LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Repeatedly getting command substitution: line 3: syntax error near unexpected token (https://www.linuxquestions.org/questions/linux-general-1/repeatedly-getting-command-substitution-line-3-syntax-error-near-unexpected-token-829479/)

dontob 08-31-2010 05:29 AM

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.....

theYinYeti 08-31-2010 07:00 AM

There is just a dollar missing before the opening-parenthesis.

Yves.

dontob 08-31-2010 07:27 AM

Hello boss,

cpu.sh: line 4: $(awk {print'$2'} > new.txt): ambiguous redirect

druuna 08-31-2010 07:45 AM

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.

dontob 08-31-2010 07:57 AM

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

druuna 08-31-2010 08:02 AM

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.

dontob 08-31-2010 08:15 AM

Thanks for your valuable time.It worked.

Kenhelm 08-31-2010 08:23 AM

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.

druuna 08-31-2010 08:26 AM

Quote:

Originally Posted by dontob (Post 4083508)
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).


All times are GMT -5. The time now is 06:03 AM.