Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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.

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?

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"
ficheck 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.

![]() |
![]() |
![]() |

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