Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help with simple script to find PID of process Post 302727055 by thirdcoaster on Monday 5th of November 2012 03:22:34 PM
Old 11-05-2012
Unfortunately that didn't work either. I made the suggested change and get the following:

Code:
root@quartz>/var/opt/OV/bin/instrumentation> ./cq_mon.sh cq_mon
invalid argument count
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]
./cq_mon.sh[57]: jps:  not found
Process is not running

My concern here is that the process is in fact running...previously it would at least echo the right message. My question is now whether something is wrong with that last 'if' line:

Code:
if [ `jps -l | grep cq | wc -l` -eq 0 ]

is being run from the right dir, since the error indicates that jps is not found. Smilie

---------- Post updated at 03:22 PM ---------- Previous update was at 03:10 PM ----------

Quote:
Originally Posted by RudiC
Not sure how far your SUN OS / shell supports this, but you might want to try
Code:
 jps -l | grep [c]q && echo "proc running" || echo "proc not running"

grep will leave an exit code: 0 if found, 1 if not found. && will execute the next statement, or even list, if found; || will do if not found. The [c] makes grep not find itself; and you may want to be way more specific in the process pattern that you grep for.
I appreciate you explaining what each piece does, THANK YOU! I am bumping up against the same problem though, the command jps isn't being found. Somehow I think I need to pass the location of jps from the first part of the script into the bottom.

Code:
root@server>/var/opt/OV/bin/instrumentation> ./cq_mon.sh cq_mon
invalid argument count
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]
./cq_mon.sh[57]: jps:  not found
proc not running


Last edited by thirdcoaster; 11-05-2012 at 04:11 PM.. Reason: missed a bracket
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies

2. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

3. UNIX for Dummies Questions & Answers

How to find the details of the previously running process with PID

OS: Unix or Linux I (only) know the pid of the process which was running earlier (say 5 hrs back) but it is not running now. Is there a way I could find the details of that process? (atleast the name of the process). Please let me know. (2 Replies)
Discussion started by: vijay.d
2 Replies

4. Shell Programming and Scripting

Find shell process pid launched throug `at`.

Hi. I was testing some staff and wrote simple script, which only writes date to log every 15 seconds. Like that #1.sh while true;do echo `date` >> 1.log sleep 15 done And than i ran this process with `at -s -f 1.sh now`. And now it is running and i don't know how to catch it. I tryed... (1 Reply)
Discussion started by: kukuruku
1 Replies

5. Shell Programming and Scripting

grab PID of a process and kill it in a script

#!/bin/sh who echo "\r" echo Enter the terminal ID of the user in use: echo "\r" read TERM_ID echo "\r" ps -t $TERM_ID | grep sh echo "\r" echo Enter the process number to end: echo "\r" read PID echo "\r" kill -9 $PID What this code does is ultimately grab the PID of a users sh... (6 Replies)
Discussion started by: psytropic
6 Replies

6. Shell Programming and Scripting

find pid of process run in specific location

Hello, I have a process a.out that runs from /a and /b How can I get the pid of the one running from /a ps -C /a/a.out does not work Thanks! (4 Replies)
Discussion started by: JCR
4 Replies

7. Solaris

how to find PID of a runnign process ?

Hi Friends, How can we find the process ID of a running process using the process name. In AIX I used to use the command "ps -ef | grep <process name>", it used to give me the owner of that process, Process ID and the threads running and the name of the process in the end. However in... (2 Replies)
Discussion started by: sahilsardana
2 Replies

8. Shell Programming and Scripting

Find PID for a process

I want to kill a process run by a user of another group. How do I do that..? (3 Replies)
Discussion started by: Haimanti
3 Replies

9. Shell Programming and Scripting

Find the Pid and Kill the Process after a Few Minutes

hi guys i had written a shell script Display Information of all the File Systems i want to find the pid and kill the process after few minutes.how can i obtain the pid and kill it??? sample.sh df -a >> /tmp/size.log and my cron to execute every minute every hour every day * *... (5 Replies)
Discussion started by: azherkn3
5 Replies

10. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies
All times are GMT -4. The time now is 06:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy