Computing.Net > Forums > Unix > Unix Monitoring Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix Monitoring Script

Reply to Message Icon

Name: jamdee
Date: July 16, 2003 at 07:36:30 Pacific
OS: Solaris 8
CPU/Ram: e10k
Comment:

Hi,

I would like to write a script that could monitor my unix domains on my e10k to page and email me in case on goes down from whatever problems. How can I automate a script to either ping, telnet, or run some form of connection check around the clock maybe every thirty to monitor the system?



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: July 16, 2003 at 08:04:59 Pacific
Reply:

There are numerous steps to what you want to do. I'm going to go on the assumption that you know how to write a script to do the check and then send a page or email if necessary.

Then the next step is to cause this script to run every 30 minutes or however often you decide is desired.

The normal way to schedule things like this is to use 'cron'. I believe that there is something called 'at' but I've never used it.

To learn about using cron, try "man cron" & "man crontab". It's pretty easy once you are used to it.

"crontab -e" will open the cron file in an editor so that you can add/change an entry.

An entry might look like:

25,55 * * * * /usr/bin/myscript >>/usr/logs/myscript.log 2>&1


The above entry will execute '/usr/bin/myscript' at 25 and 55 minutes after every hour and will append all output to the file '/usr/logs/myscript.log'.

25,55 5 * * * /usr/bin/myscript >>/usr/logs/myscript.log 2>&1

this entry will execute at 5:25 & 5:55.

One thing to pay attention to when running scripts/programs with cron is that the PATH used by cron may not be the same as when you run the script/program from the command line. So typically, you use full path names for any commands and programs.


0

Response Number 2
Name: jamdee
Date: July 16, 2003 at 11:00:59 Pacific
Reply:

Hi and Thanks for your feedback.

I was actually trying to be as brief as possible in the message when I wrote it but I should've been more specific on what I need help with. I'm quit familiar with using cron, but to actual write the script I need more insight on what to do if If I can't connect such as how to trap errors, what commands to use to read the feedback once I try to telnet or ping. So if I use the "if-then-else commands" if it doesn't connect how do I read that error in the script and what to do from there?


0

Response Number 3
Name: David Perry
Date: July 17, 2003 at 04:55:01 Pacific
Reply:

Read the return code of the command.

ping -c 1 hostname >/dev/null 2>&1

rc=$?
if [ $rc -gt 0 ] ; then
echo "process for error"
else
echo "success"
fi

check the man pages for the implementation of ping. You want a fixed ping count. Scripting telnet is a chore. rsh might be the answer or you could look at expect.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix Monitoring Script

Unix mail script www.computing.net/answers/unix/unix-mail-script/1201.html

Unix Shell Script www.computing.net/answers/unix/unix-shell-script/3580.html

Unix shell script for opening a file and www.computing.net/answers/unix/unix-shell-script-for-opening-a-file-and/3452.html