ps aux + grep + nice + while


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ps aux + grep + nice + while
# 8  
Old 11-23-2012
Ah... So its not a true system backup then... So I suppose the peak you get is when it is actually zipping when is to be sent...
Maybe all you have to do is to monitor the phenomenon, if it is that, then write a script to point out the process from your alert
# 9  
Old 11-23-2012
that is exactly what i'm doing vbe Smilie a .sh to make the process go down in priority a bit not too much and relase some load on the task ( lower the cpu load ) and prevent the alert on my email from the CPU Health monitor Smilie
# 10  
Old 11-23-2012
Will this work for you?
Code:
if [ $( ps -ef | grep -v grep | grep -c backup ) -eq 1 ]
then
      UNIX95= ps -ef -o pid,pcpu,args | grep backup | grep -v grep | read _PID _CPU _ARGS
      if [ ${_CPU} -gt 95 ]
      then
            # renice priority ${_PID}
      fi
fi

This User Gave Thanks to Yoda For This Post:
# 11  
Old 11-24-2012
hmmm why, not a while loop to keep track if the process is on or not.
# 12  
Old 11-26-2012
well bipinajith i have your script on my crontab.hourly Smilie small question why you have the the read parameter on the UNIXPROC ... variable and why you dont refer to the unixproc to find the values on the if -gt 95 ?
# 13  
Old 11-26-2012
This one does work on my linux/bash system; not sure it will on yours as you don't mention details:
Code:
while read PID CPU REST < <(ps -eo pid,pcpu,args|grep [b]ackup)
      do echo $CPU
         sleep 2
      done

This one will print the backup process' CPU percentage every other second. Replace echo with what you need, e.g. if [ "$CPU" -ge 95 ]. If the process does not exist or disappear, so does the loop. Make sure you only grep the one backup process of interest, eventually you have to narrow down the grep pattern.
This User Gave Thanks to RudiC For This Post:
# 14  
Old 11-26-2012
Code:
while read PID CPU REST < <(ps -eo pid,pcpu,args|grep [b]ackup)
      do 
         if [ "$CPU" -ge 95 ]
         then
           renice -1 $PID
         fi   
         sleep 2
      done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the exact process using ps aux command?

Please do not post a technical question in the @How to contact....' forum. I have moved this for you. Hello Everyone, Please help me on this, Requirement here is to check whether the process is running using the process id. For the below scenario, I m trying to grep 1750 process id to... (3 Replies)
Discussion started by: Hari A
3 Replies

2. Shell Programming and Scripting

Get PID Number from “ps aux --sort -rss ”

Hi everyone How can I just get the PID of the following command: ps aux --sort -rss Thanks Regards (2 Replies)
Discussion started by: anonymuser
2 Replies

3. AIX

Run ps aux continuously in AIX

Requirement is to monitor cpu usage /process for a user given time and record the output. topas,topasout,topasrec,tprof not seems to be working for me. so what i am looking for is to run below command continously till the time limit given by the user who runs the script.since below command is a one... (6 Replies)
Discussion started by: NarayanaPrakash
6 Replies

4. Shell Programming and Scripting

Extract a column from ps -aux command

Hi, I have the following output : root 9296 81.7 0.2 1115328 20856 ? Sl 14:38 1:00 /opt/h264rtptranscoder.bin --videoPort=14500 --audioPort=14501 --serverPort=14500 --framesPerSecond=50 --profilesPath=/opt/transcodingProfiles I would like to have the following output : ... (6 Replies)
Discussion started by: liviusbr
6 Replies

5. AIX

Difference between ps -ef and ps aux

Hi, Can someone tell me what the difference is between ps -ef and ps aux. I was under the assumption that both commands would list ALL processes currently running on the system. But on my server I find the following: # ps -ef | wc -l 519 # ps aux | wc -l 571 What... (1 Reply)
Discussion started by: petervg
1 Replies

6. Shell Programming and Scripting

Need to get the list of file with size in AUX

to get the list of file name with size Example: rwxrwxrwx 1 cm x 562KB Nov 6 19:22 a rwxrwxrwx 1 cm x 562MB Nov 6 19:22 a edit by bakunin: Please view this code tag video for how to use code tags when posting code and data. (5 Replies)
Discussion started by: Jewel
5 Replies

7. Programming

nice command and nice() system call

Hi I want to implement the nice command in the shell that I am building. I came to know that there is a corresponding nice() system call for the same. But since I will be forking different processes to run different commands typed on the command prompt, is there any way I can make a command... (2 Replies)
Discussion started by: tejbuch
2 Replies

8. UNIX for Dummies Questions & Answers

ps aux|grep getty

what is the aim of this command: ps aux|grep getty (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

9. UNIX for Dummies Questions & Answers

PS -aux and PS

I am new to the Unix. Can someone tell me what is the difference between 'PS' command and 'PS -aux"? Isn't 'PS' mean the current running process? Isn't 'PS -aux' mean the current running process too? If they are the same, how come 'PS -aux' always has a lot more listing than 'PS'? Thanks, (4 Replies)
Discussion started by: a2715mt
4 Replies

10. Post Here to Contact Site Administrators and Moderators

Very Nice

Just a quick message to say great work to Neo and any others who have helped with the upgrade - the layout, appearance and functionality of this forum ROCKS. By far the best I have seen. Excellent! (1 Reply)
Discussion started by: alwayslearningunix
1 Replies
Login or Register to Ask a Question