Bash Awk Variable problem
Dear all,
I want to find a PID of a certain program. I have same program running with different parameters and want to find the PID based on the parameter ./program conf1.conf ./program conf2.conf ./program conf3.conf So I Used: #!/usr/bash ... $param_name = $1 pid=$(ps x | grep ./program | grep $param_name | gawk "{ print $1 }") ... My problem is that when I use this command in my script file, $1 is replaced by the script's frist parameter I mean ./myscript conf1 causes pid=$(ps x | grep ./program | grep conf1 | gawk "{ print conf1 }") and so the $pid variable remains empty. Any ideas? |
You are not escaping the $ or using single quotes to prevent substitution, so of course the parameter is substituted. You want to pass the string '$1' to gawk, not the value of $1.
Either of these should work: Code:
pid=$(ps x | grep ./program | grep $param_name | gawk '{ print $1 }') |
Just an idea: why not use pgrep?
Quote:
|
I second pgrep
|
Thanks to macemoneta
but unfortunately both ways did nothing :( I'm trying pgrep and pkill Thanks to taylor_venable :) |
Thanks Pkill was great.
|
All times are GMT -5. The time now is 09:52 AM. |