Syntax error with ps command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error with ps command
# 1  
Old 01-20-2017
RedHat Syntax error with ps command

i am trying the blow command in vain on Linux Terminal.

Code:
kill -9 `ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}'`
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

kill -9 $(ps -eaf | grep weblogic.NodeManager | grep wls103| awk '{print $2}')
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

kill -9 ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}'
bash: kill: ps: arguments must be process or job IDs

Can you please suggest what will work ?
# 2  
Old 01-20-2017
This begs the question, what is the output of ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}' ?

...which you could reduce to ps -eaf | awk '/weblogic.NodeManager/ && /wls103/ { print $2}' anyway.

Also, why are you running kill -9? Have you attempted to give this job a chance to quit gracefully before trying the nuclear option?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-20-2017
Error

Quote:
Originally Posted by Corona688
This begs the question, what is the output of ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}' ?

...which you could reduce to ps -eaf | awk '/weblogic.NodeManager/ && /wls103/ { print $2}' anyway.

Also, why are you running kill -9? Have you attempted to give this job a chance to quit gracefully before trying the nuclear option?
The output of ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}' is 10997 which is the pid i wish to kill -9 on purpose.

can you please suggest why my commands fails as shown in the OP Post#1
# 4  
Old 01-20-2017
Probably because the PID you're looking to kill doesn't exist. Either that, or ps looks different on your system than the system this came from.

I repeat, why kill -9? This is usually a bad idea.
# 5  
Old 01-20-2017
I'm pretty sure this has been suggested before, but running a command with the shell's xtrace option set will explicitly show HOW the command is called and HOW its parameters are expanded.
# 6  
Old 01-20-2017
Specifically, your first command would have worked if your long pipe chain had actually printed a PID.

Your second command would also have worked if your long pipe chain had actually printed a PID.

The third is obviously wrong.

So the question is, what is that long pipe chain of yours doing.
# 7  
Old 01-21-2017
The grep and awk appear in the ps list, so ps *can* find them (race condition). Escape your search expressions, so they are not matching in the arguments.
Put one character in [ ] to achieve that.
With only awk
Code:
pids=`ps -eaf | awk '/[w]eblogic.NodeManager/ && /[w]ls103/ {print $2}'`
[ -n "$pids" ] && kill $pids

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command syntax error in cron

SCO OSR 507, user's shell is old Bourne sh The same command is OK when run using now, but fails when run in cron, see below: 1) using now, see how it worked and I see resulting DT=2018 in the mail $ at now { dt=`/usr/gnu/bin/date '+%Y'`; echo "DT=$dt"; } job 1522867418.a-6605:0 at Wed... (2 Replies)
Discussion started by: migurus
2 Replies

2. Shell Programming and Scripting

Getting syntax error while running awk command

Hello Gurus, I am firing the below command : df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}' But I am getting the below error:- ====== syntax error The source line is 1. The error context is {if ($4 > >>> 90%) <<< awk: The... (9 Replies)
Discussion started by: pokhraj_d
9 Replies

3. Shell Programming and Scripting

Syntax error piping to bc on command line - works when assigned to var

I have a script which outputs some timing data a line at a time. There are approx. 10 lines echoed, each line looks something like this: 0.741 http://checkip.dyndns.org 94.170.119.226Since I needed to add all the values in the first column, I piped the output to grep, matching and printing the... (7 Replies)
Discussion started by: gencon
7 Replies

4. Shell Programming and Scripting

Syntax error using do command

i have the following do command: while IFS =: read printer drv IP port do echo -e "$ printer: \ n \ drv: \ t $ drv \ n \ IP: \ t $ IP \ n \ port: \ t $ port \ n \" done < diffs.txt receiving the following error: syntax error at line 37 : `do' unmatched something is... (2 Replies)
Discussion started by: ggoliath
2 Replies

5. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

6. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

7. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

8. Shell Programming and Scripting

if else command syntax error

can anyone tell me what`s going wrong with my if else statement? set exam=(AAA BBB CCC) foreach ii ($exam) if ($ii -eq "AAA") do echo "PASS" else echo "FAILED" done end (4 Replies)
Discussion started by: c0384
4 Replies

9. Shell Programming and Scripting

until command syntax error

Hi there. I spent too much time away from Unix, now I can't remember how to issue a simple until command in ksh :mad: could you tell me what is wrong with the following code sample: export v = "1" until do echo 'executing repeat_until' v = `expr $v + 1` done I've... (3 Replies)
Discussion started by: 435 Gavea
3 Replies
Login or Register to Ask a Question