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

Posted on 2009-05-22
Medium Priority
Last Modified: 2013-12-26


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
Question by:sunhux
  • 3
  • 2

Author Comment

ID: 24456614

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
                                    ^                                            ^
LVL 51

Accepted Solution

ahoffmann earned 1500 total points
ID: 24460785
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.

Author Comment

ID: 24466246

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
LVL 51

Assisted Solution

ahoffmann earned 1500 total points
ID: 24500584
opps typo, sorry
I used the sar command as you posted and inserted the -, please use instead
  sar -v 2 29| ....

Author Closing Comment

ID: 31584627
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"

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

619 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