Grep command to show only process name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep command to show only process name
# 1  
Old 12-09-2010
Grep command to show only process name

Can I modify the grep command to show only a process name?

Currently I run ps -efa | grep chk_web to get the following:

Code:
mousr  3395     1  0 09:36:06 pts/10   0:00 sh /var/opt/scripts/chk_web.sh

Can this be changed in any way to get only:

Code:
/var/opt/scripts/chk_web.sh or chk_web.sh.

I know that if I run:

Code:
ps -efa | grep chk_web.sh |grep -v 'grep '|sed 's/^[^0-9]*\([0-9]*\)[^0-9].*$/\1/'

I will get the process ID.

Last edited by radoulov; 12-09-2010 at 07:42 AM.. Reason: Code tags, please!
# 2  
Old 12-09-2010
Code:
ps -eo args | grep [c]hk_web

If the above errors out, tell us which OS you're using.
# 3  
Old 12-09-2010
To get /var/opt/scripts/chk_web.sh:
Code:
 
ps -efa | grep chk_web.sh |grep -v 'grep ' | awk '{print $NF}'

TO get chk_web.sh:
Code:
 
basename $(ps -efa | grep chk_web.sh |grep -v 'grep ' | awk '{print $NF}')

# 4  
Old 12-09-2010
All work. Cheers folks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command to show the number of results

Hi I wanted to know if there is an option in grep command to show the number of results (not the number of lines of findings). Thanks (14 Replies)
Discussion started by: abdossamad2003
14 Replies

2. Shell Programming and Scripting

Ensuring certain processes do not show up in process table

i've read somewhere a long time ago that there's a way to hide the workings of a script in sub functions so that when run, it doesn't show up in the process table. is this really possible? for instance, i need to run a command that has a password in it. and when that;s being run, it can be... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. UNIX for Advanced & Expert Users

Grep show file name once

I am using grep as follows grep --include \*.org -ir "sunspot" -C 3 ./astron_aphys/solarsy/sun/helioseism/localhs/fhankel/ This gives me the filename for each matched line. How can I change the command to print the file name only once rather than having the same file name repeated at... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

Show running process command > 60 chars

Hi. I use this command to get list of running process: ps -ef|grep ICP|grep -v grep But how do I set the terminal to show full command? It seems that it always truncated to 60 chars no matter what options I put. e.g output oracle9 25011 24998 0 03:00:05 ? 0:00 /usr/bin/sh... (14 Replies)
Discussion started by: aimy
14 Replies

5. Shell Programming and Scripting

Using backspace in echo to show process count

i have something like this tablesName="abc def hij akn ... etc etc" count=0 for i in $tablesName do echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\bTableCount: $count" count=`expr $count + 1` done the above is just a description wha i need is when the loop executes the... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

7. Shell Programming and Scripting

does the pid of background process show in /proc?

Hi all, I'm reading <advanced bash scripting> and there is a example to kill a background process in a limited time,as shown below: #! /bin/bash #set -n TIMEOUT=$1 count=0 hanging_jobs & { while ((count < TIMEOUT));do eval ' && ((count = TIMEOUT))' ((count++)) sleep 1... (6 Replies)
Discussion started by: homeboy
6 Replies

8. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

9. Shell Programming and Scripting

How to show progress bar for a running process

Hi, I have 2 shell scripts ,one for taking hot backup of oracle Database while other is for progress bar. But I don't have an idea hoe should I incorporate the shell script of progress bar in my hot backup code . Please help. My shell script for hot backup is as below: ... (0 Replies)
Discussion started by: dwiravi
0 Replies

10. UNIX for Advanced & Expert Users

ps | grep command not returning existing process

Hello all, I develop an ERP application that runs on a number of *nix flavors. This application had been around for quite a number of years. As part of the application launch, we do a check for a background process using the following command: ps -ef | grep -v grep | grep mi\/ba | grep... (6 Replies)
Discussion started by: jlitzie
6 Replies
Login or Register to Ask a Question