Solved

Bash script

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ion my script output i have multiple cvs files 3 40
RoboCopy to Changing External Drives 2 60
replacing file name with spaces in ibm aix. 2 32
Shell Script- gzip 5 45
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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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