Solved

Bash script

Posted on 2011-02-26
2
445 Views
Last Modified: 2012-05-11
Hi Group

I am trying to write a bash script that will run every 30 minutes in cron that will search for all process`s owned by user bob and renice them to the value of 10.

I seem to have the logic of the script but I am unable to glue things together.

1. Firstly we need to obviously get the process`s owned by user bob - so something like ps aux | grep bob - this will gives us all the process owned by bob

2. We then need to return the process id for every process owned by bob and set the niceness to 10.  So am thinking we need to use something like the cut command to return the pid column

3. We will probably need a loop to iterate through every process id and set the nicessness to 10 using the "renice -n 10 PID"

I have the logic but am unable to put it together. Any help would be really appreciated.

Thanks.
0
Comment
Question by:tuxracer
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 34990162
Assuming your system, you can do

pgrep -u bob | xargs renice -n 10

Open in new window


if you don't have renice

ps -u bob | awk '/[0-9]/ {print $1}' | xargs renice -n 10

Open in new window

0
 

Author Closing Comment

by:tuxracer
ID: 34990169
Hi Tintin

Excellent! I sometimes just think too deep and get carried away with the actual result....

Thank you so much for your help.

Much appreciate!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question