Solved

Bash script

Posted on 2011-02-26
2
443 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now