[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Bash script

Posted on 2011-02-26
2
Medium Priority
?
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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 …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

650 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