1

I am writing a script where I need to pass the variable value inside the awk code block like this

$ ps auxw |awk /$variable/ |awk !/awk/ |wc -l

For example. If I were to check the status of cron I would type something as shown below 
$ ps auxw |awk /cron/ |awk !/awk/
root      4980924  0.0  0.0 1276 1300      - A      Jan 07  3:12 /usr/sbin/cron

I had used ps -ef |grep cron |grep -c -v cron however when I executed the script, it would report the line count of two when I had only one line output. Could someone help?

rony thomas
  • 215
  • 1
  • 12
  • Do you mean you used ps -ef | grep cron | grep -c -v grep? – James McLeod May 13 '20 at 10:36
  • @JamesMcLeod, ps command as you have shown works however when it is called inside a script the line count is 2 when the actual count is 1 for some strange reasons in ksh – rony thomas May 13 '20 at 10:40

1 Answers1

1

I guess, I have got the answer for what I was looking for. I had to just pass variable inside double inverted commas. Thank you.

$ svar="cron"
$ ps auxw |awk /"$svar"/ |awk !/awk/
root      4980924  0.0  0.0 1276 1300      - A      Jan 07  3:12 /usr/sbin/cron
rony thomas
  • 215
  • 1
  • 12