- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scipt help please ..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2001 08:20 AM
08-11-2001 08:20 AM
I have been working with this script that I attached that I didnt write. I have taken stuff out and got what I need but I am missing one part.First here is the output of the script that is goinging into a txt file. And here is the output:
Sat Aug 11 10:32:56 CDT 2001
cnrint is running OK as PID 22996
Three items below should all be close to 10
DHCP Health is 10
DNS Health is 10
TFTP Health is 10
I need to add an if statement that if cnrint is not running it will send out an email.
And if the DHCP DNS or TFTP Health is less then 10 it will send out an email. Relay and everything is set up. I just dont know where to add the commands to make it do this.
Thanks
Richard
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2001 08:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2001 08:33 AM
08-11-2001 08:33 AM
Re: scipt help please ..
you already have the needed "if" in there in
"cnr_status"...
CNRINTPID=`cnr_pid`
if [ $CNRINTPID -ne 0 ]; then
echo `date`
echo ""
echo "cnrint is running OK as PID $CNRINTPID"
else
echo "cnrint is NOT RUNNING!"
-> echo "cnrint is NOT RUNNING!" |
-> mailx -s"cnrint NOT RUNNING" root
fi
echo
echo "Three items below should all be close to 10"
echo "DHCP Health is "`item_health dhcp`
echo " DNS Health is "`item_health dns`
echo "TFTP Health is "`item_health tftp`
-> if [ "$(ietm_healt dhcp)" -lt 10 ]
-> then echo "DHCP Health is "`item_health dhcp` |
-> mailx -s"DHCP" root
-> fi
...and similiar for the other "items".
HTH,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2001 08:40 AM
08-11-2001 08:40 AM
Re: scipt help please ..
To add an email alert if cnrint is not running, after the statement (or as a substitute to the statement:
echo "cnrint is NOT RUNNING!"
...add:
mailx -s "Alert: cnrint is NOT running!" root < /dev/null > /dev/null
...this will mail 'root' the message shown. Since there is no message body, I substituted /dev/null. Since 'mailx' will helpfully offer the response that there is no message body, I suppress that by redirecting stdout to /dev/null.
In a similar fashion, you can constuct email messages for your other conditons.
If you want to generate one alert, you could echo all of your messages into one file and use that file as the message body to 'mailx', like:
mailx -s "Alert!!!" root < /tmp/alert.$$
Notice, again, that here I didn't redirect stdout to /dev/null. That's because 'mailx' is "happy" it found a non-null message body in the form of the /tmp/alert.$$ file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2001 07:13 PM
08-11-2001 07:13 PM
Re: scipt help please ..
grep does not care what it matches. To grep for cnrint means that multiple hits can occur and this will confuse the script. For instance, programs like cnrint3 and 9cnrint will match, and even a user login called cnrint will match--not good as it may work today and break next week.
Instead, use the little known -C option of ps which will return exact matches for process names. To use this feature, ps must run in UNIX95 mode. For example:
UNIX95= ps -C sh
which will show only sh and NOT ksh (grep will fail in this task by matching csh and ksh and even bash as well as usernames containing sh).
And just to keep the script healthy, count the number of occurances from ps -C. There is always the possibility of multiple copies and this may be an error that should be reported.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2001 09:43 PM
08-12-2001 09:43 PM
Re: scipt help please ..
I can post now what a great thing!!
Anyway I applied all of your ideas. And they all give me the final result. Now does it matter what I use? My goal is to write smart scripts. Not just shell scripts but smart scripts.
Mr Bill
your info on the ps -C option is great.So I should use
UNIX95= ps -C cnrint |awk '{print $1}'|grep -v PID
to grep for the PID in the script or should I use another syantax?
Thanks
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2001 03:54 AM
08-13-2001 03:54 AM
Re: scipt help please ..
With regard to your last question. I?d change the syntax Bill suggested slightly.
The syntax he recommends returns a list of a zero or more processes. The first issue is that a descriptive header line is returned (?PID TTY TIME CMD?). We don?t want this at all, and really, all we want is the first column which is the ?pid? we?re interested in. We can do this in one stroke as:
PIDS= PIDS=`UNIX95= ps -C cnrint|awk 'NR>1 {print $1}'`
Then, as Bill suggested, you might want to count the number of matches you found. This too is easy.
N=`echo $PIDS|wc -w`
case $N in
0 ) echo "no matches"
;;
1 ) echo "one pid returned"
;;
* ) echo "more than one pid returned!"
;;
esac
Regards!
...JRF...