Pls Help me out ... I want to check process status at regular intervals of time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pls Help me out ... I want to check process status at regular intervals of time
# 1  
Old 07-26-2008
Java Pls Help me out ... I want to check process status at regular intervals of time

I want to check process status at regular interval of time ...
so i ha wirtten this BUT its not working when i placed this peace of code in .sh ..
please help me out

#!/bin/sh
w = ps -ef|grep processname | wc - l
echo $w
if [ $w -lt 3 ] ; then
Banner "Proceesname Problem"
else
Banner " Running Fine"
fi

Please help me out with necessary modification .
Thanks in advance...
# 2  
Old 07-26-2008
try code tags....

Code:
#!/bin/sh
w = $(ps -ef|grep $processname | grep-v 'grep' | wc - l )
echo $w
if [ $w -lt 3 ] ; then 
echo "$processname Problem"
else 
echo " Running Fine"
fi

# 3  
Old 08-02-2008
hi jim,
Thank you very much,
I got the solution and the problem is when we are trying taking variable "w" it is giving some errors i think "w" is internal system parameter .
I tried it with taking "t" as variable it got executed.

Thank you once again for helping me out JIM.

Lastly i have one dought "ps -ef|grep $processname | grep-v 'grep' | wc - l"
why did you grep -v 'grep' i havent used like this any time.
# 4  
Old 08-02-2008
Hi Srini,

grep -v 'grep' would tend to filter the process output, not to include grep process.. Remember that it may be included as a process, and would confusions. So to be safe, that was added...
Quote:
Originally Posted by srinivasvandana
hi jim,
Thank you very much,
I got the solution and the problem is when we are trying taking variable "w" it is giving some errors i think "w" is internal system parameter .
I tried it with taking "t" as variable it got executed.

Thank you once again for helping me out JIM.

Lastly i have one dought "ps -ef|grep $processname | grep-v 'grep' | wc - l"
why did you grep -v 'grep' i havent used like this any time.
# 5  
Old 08-02-2008
Quote:
Originally Posted by srinivasvandana
...
w = ps -ef|grep processname | wc - l
echo $w
if [ $w -lt 3 ] ; then
....
You can replace ps, grep and wc by pgrep
Code:
#!/bin/sh
if [ $(pgrep -c processname) -lt 3 ] ; then 
       echo "$processname Problem"
else 
       echo " Running Fine"
fi

# 6  
Old 08-02-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check status of process

Hi All, Have a query How to check for a process and if down start it , try if for 2 times and its not starting don't do it My code is working to some extent but while starting try starting both times. Please advise , whats wrong here ? if you have any other approach please do share. My... (1 Reply)
Discussion started by: abhaydas
1 Replies

2. Shell Programming and Scripting

Script to check process status

Hi Team, I am using redhat 6.4 version server.We have a script which is used to check the process and sends email if the process is not running.If it is running it will continue and do some other operation. I didnot understand below option -z in the if condition.I have tried to... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

3. UNIX for Dummies Questions & Answers

Bulk load testing in regular intervals

I need to write a script which can send files via sftp communication continously for half an hour or any given duration of time. I have already written a batch file to send multiple file via SFTP. but I need to know how can we set a duration of half an hour through shell script. Can we use sleep... (2 Replies)
Discussion started by: talk1234
2 Replies

4. Programming

Selecting files in regular intervals from a folder

Hi, I need your expertise in selecting files from a folder. I have files named with convention: filename.i.j where j is an interger from 1 to 16, for each i which is an integer from 1 to 2000. I would like to select the files with i in regular interval of 50 like filename.1.j,... (2 Replies)
Discussion started by: rpd25
2 Replies

5. Shell Programming and Scripting

Remove a block of Text at regular intervals

Hello all, I have a text files that consists of blocks of text. Each block of text represents a set of Cartesian coordinates for a molecule. Each block of text starts with a line that has a only a number, which is equal to the total number of atoms in the molecule. After this number is a line... (15 Replies)
Discussion started by: marcozd
15 Replies

6. Shell Programming and Scripting

How to check the process status

Hi, I have a cron job which runs every ten minutes, now i hav to check the process whether it is running or not only once and then this should be sent to a log file.. crontab : 00,10,20,30,40,50 * * * * a process check ps = 'ps -ef |grep a ' if then echo " Success" >... (3 Replies)
Discussion started by: NehaKrish
3 Replies

7. Shell Programming and Scripting

How to Check the process Status and do something

Hi we have weblogic deployed under Linux Enterprise 5 . Now i want to write a script that checks if weblogic is running or not I have found that weblogic uses Java as process . Can i do this way : my Script File : Echo Checking Status if then echo Server Running else echo... (2 Replies)
Discussion started by: Ravi Pavanv
2 Replies

8. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

9. Programming

performing a task at regular intervals

hi! i m tryin to write a program that will perform a specific tasks after fixed interval of time.say every 1 min. i jus donno how to go abt it.. which functions to use and so on... i wud like to add that i am dont want to use crontab over here. ny lead is appreciated. thanx. (2 Replies)
Discussion started by: mridula
2 Replies

10. Shell Programming and Scripting

mailing myself at regular intervals...

hi all, i wrote a script to mail myself using pine (modified) to keep remind of b'days. #!/bin/bash grep "`date +%D |awk -F/ '{print $2+1, $1+0}'`" dataFile >/home/username/mailme if test -s /home/username/mailme then pine -I '^X,y' -subject "Birthday Remainder" username... (4 Replies)
Discussion started by: timepassman
4 Replies
Login or Register to Ask a Question