Question: ps ps ( process status ) is a tool that lists running processes. By default, it lists only your own processes. Since we want to
ps
ps process status is a tool that lists running processes. By default, it lists only your own
processes. Since we want to look at other users we will want to use at least the flag a ps
doesnt use for its options, so this would just be ps a Well also want to know about
hidden processes, so need the x flag, and we need to get extra information so need the u
flag. The command you have will now give you a list of all processes and a lot of information
about them.
grep
grep allows us to search for a specific pattern. We can take the output of ps and pipe it to
grep to search for a pattern and return only lines with that pattern.
cut and tr
If we want to extract specific information from our ps output we can use cut which allows
you to specify a delimiter with d we can then say which field we want with fyou can
also use character ranges with c For fields sometimes its helpful to use tr to s squash
delimiters together.
sort
We can sort a file or input using the sort command. You might need the r flag to get the
order you want. You might also need the h flag to sort numerically.
head
We can get just the first few items in a file or input using the head command. The n flag
changes the number of lines.
Making MiniMon Points
Get RSS usage for a user
Using the above create a BASH script called minimon.sh In your script write a function
that takes a username as an argument, and then uses ps grep, tr and cut with pipes to
return the RSS resident memory that the user is consuming.
Combine RSS usage for a user
Write a second function that can take the output of the above and sum all the values.
Find largest RSS usage for a user
Write a third function that takes the output from the first and finds the largest single RSS
usage peak
Combine RSS usage for a user
Finally, write the main body of your loop to use the above functions to compute the total
RSS and peak RSS for a user given as a parameter. The output must be printed as:
:
Where and are replaced by the correct respective
values. Your log should follow exactly this format
Alerting Points
Extend your script to allow a third parameter which is the alerting threshold. This should
be compared to the total and peak RSS If either exceeds this value then a message should
be output on stderr. This message should have the following format:
ALERT: : exceeded RSS threshold ##peak total
Where is replaced by its correct respective value, ## is the peak or total
value that exceeded the threshold, and peak total is replaced by either peak or
total depending on which caused the alert condition. Your alerts should follow exactly
this format To print to stderr well need to use a redirecting trick: &
This tells bash to redirect stdout to stderr It can also be used the otherway if you need errors
in output for your scripts ie&
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
