Unix HP-UX Shell script to check nfile ninode nproc used and alert/email if it's high


 Hi

Our B11.11 PA-RISC (with 4GB RAM) limits for nfile and ninode (& possibly nproc)
have been hit lately, so we have just increased them and would like  a script to monitor
if these new values' are being eaten up by runaway processes as sar below shows:

10:04:37 text-sz  ov  proc-sz  ov  inod-sz  ov  file-sz  ov
 10:04:57   N/A   N/A 577/1620  0  1867/1988  0  3315/3339  0
 10:05:02   N/A   N/A 578/1620  0  1869/1988  0  3323/3339 22

So in above's readings, 3315 and 3323 are dangerous levels which could
have hit nfile limit of 3339 that resulted in our users unable to retrieve data
(users use IE to access a Wintel webserver and this webserver retrieves
 data from our HP-UX Oracle Filenet server)


So I'll need a script that will email/alert me if it utilization exceeds 65% of current limits.

The Shell script will do the following  (this script will run every minute from cron) :
sar -v 2 29
(every 2 sec for 29 times, did not want to do 30 times to prevent race condition ie
 before next script starts)
 
if utilized value exceeds 65% for each of the nfile, ninode, nproc, email me to alert

Hope it will not chew a lot of CPU resource for running sar so frequently
sunhuxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunhuxAuthor Commented:

Btw, the script needs to have condition such that if it has alerted me via email, it should wait
30 minutes before it next alert me so that I don't get too many emails.

But when it exceeded 65%, would like it to continue to log the sar output with time+date
stamp into a file.

Btw, I'll only need to monitor nproc and nfile (leave out the ninode) :
 10:05:02   N/A   N/A 578/1620  0  1869/1988  0  3323/3339 22
                                    ^                                            ^
0
ahoffmannCommented:
sar -v -2 29|awk '($8 ~ /[0-9][0-9]*\/[0-9][0-9]/){split($4,a,"/");split($8,b,"/");if((a[1]/a[2]>0.65)||(b[1]/b[2]>0.65)){print "mail -salert you@somewhere"}}'|sh

I don't understand fully your requirement about the filename and the 30 minutes, but I assume that this should be handled by the script started by cron.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunhuxAuthor Commented:
Hi,

Got the following error when executed the "sar" line provided :

sar: illegal option -- 2
usage: sar [-ubdycwaqvmAMPS][-o file] [-p psetid] t [n]
       sar [-ubdycwaqvmAMPS][-s hh:mm][-e hh:mm][-i ss][-p psetid][-f file]

What I meant earlier is to ensure I don't keep getting emails too frequently when the
threshold is exceeded, so if it's exceeded for 2 hrs, just get 4 email alerts, instead of
every few seconds or minutes
0
ahoffmannCommented:
opps typo, sorry
I used the sar command as you posted and inserted the -, please use instead
  sar -v 2 29| ....
0
sunhuxAuthor Commented:
There's still some syntax error but decided to just measure # of oracle
processes at Unix OS level by "ps -ef | grep -i oracle | wc -l"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.