Create a script to monitor host interface up down


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a script to monitor host interface up down
# 1  
Old 07-28-2011
Create a script to monitor host interface up down

Can anyone provide me some idea. I would like to create a script to monitoring some host interface up down issue. The scirpts will be schedule very 4 minutes to keep monitor the hosts interface. I draw my deside to show how to count the up down. default count value is 11111. that mean the interface is normal. it keep in up status. if the interface change to down. than it will be change to 11110. then the scripts will count it the 0 occurence more than 1 times it will do something like sent email. How can I campare with the old log and newlog to group the records to the newlog? or maybe do you have any good idea to be more esay to finish this scripts?

Counting the occurence of "0"
Code:
# echo "10101" | awk '{ x=gsub("0",""); print x }'
2
# echo "10001" | awk '{ x=gsub("0",""); print x }'
3
# echo "10000" | awk '{ x=gsub("0",""); print x }'
4

Two table format like the follow:

old log
###########
Code:
host Ip status Count
hosta XXX.XXX.XXX.XXX Critical 11011
hostb XXX.XXX.XXX.XXX Critical 11110

###########

newlog
###########
Code:
host Ip status Count
hosta XXX.XXX.XXX.XXX Critical 11110
hostc XXX.XXX.XXX.XXX Critical 11110

###########
Final group the records to templog and replace to the old log
###########
Code:
host Ip status Count
hosta XXX.XXX.XXX.XXX Critical 10110
hostb XXX.XXX.XXX.XXX Critical 11101
hostc XXX.XXX.XXX.XXX Critical 11110

###########

Last edited by pludi; 07-29-2011 at 03:13 AM..
# 2  
Old 07-29-2011
The best proof is to keep a connection up and send data round trip, intermittently. For instance, you can ssh and sed timestamps once a minute, ensuring they are returned in 1 second. If they block or you cannot connect, it emails and exits:
Code:
#!/usr/bin/ksh
 
export LOG=/tmp/ssh.other_host.$$ FAIL_CT=/tmp/ssh.other_host.$$.ct
 
echo 0 >$FAIL_CT
 
while [ $(<$FAIL_CT) != 4 ]
do
 while [ $(<$FAIL_CT) != 4 ]
 do
  last=$( date )
  echo "
$last
" &                   # background in case pipe blocks
  sleep 1
  if ( fgrep -q "$last" $LOG )
  then
   echo 0 >$FAIL_CT
   sleep 60
   continue
  fi
  echo $(( $(<$FAIL_CT) + 1 ))>$FAIL_CT
 done | ssh other_host "cat -u"
done >$LOG 2>&1
 
(
 date "+%Y-%m-%d_%H:%M:%S ${0##*/} ($$) Unreachable: other_host
============================================"
 tail -25 $LOG
 ) | mailx -s "${0##*/} Unreachable: other_host" support_id@your_email_host

ssh sessions sometimes are timed out, so this reports if a session cannot be established or if the data flow gets blocked.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Create an unconfigured VMware host from a template that is set to do firstboot --reconfig

I have an Oracle Linux 7.1 vsphere host built. It's be preconfigured with our security configurations. What I would like to do is unconfigure this host. Then set the host to do firstboot --reconfigure. how do I do that using /etc/sysconfig/firstboot? I've tried setting ... (10 Replies)
Discussion started by: os2mac
10 Replies

2. AIX

Need a graphical interface on AIX server to create database

Hello, Please suggest me the ways how to get graphical interface on AIX server.I need to create oracle database for which I need graphical access. Best regards, Vishal (4 Replies)
Discussion started by: Vishal_dba
4 Replies

3. Homework & Coursework Questions

shell script that can create, monitor the log files and report the issues for matching pattern

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write an automated shell program(s) that can create, monitor the log files and report the issues for matching... (0 Replies)
Discussion started by: itian2010
0 Replies

4. Shell Programming and Scripting

Write an automated shell program(s) that can create, monitor the log files and report the issues for

Hi , Please help me getting this done. Write an automated shell program(s) that can create, monitor the log files and report the issues for matching pattern. (i) Conditions for creating log files. Log file is created with date (example 2010_03_27.log). If the log file size is 10 Mb for... (1 Reply)
Discussion started by: itian2010
1 Replies

5. Shell Programming and Scripting

How to create a user interface pointing to a file?

I have to create a user interface in which user can easily update ,delete or insert a new record which is pointing to a file in AIX Server? Using awk,sed ican update ,modify the file. how to create a link to userlike GUI(without using Tomcat,IIS) (3 Replies)
Discussion started by: laknar
3 Replies

6. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

7. UNIX for Dummies Questions & Answers

please suggest computer languages to create man-machine interface for Linux applicati

I am new to program development on Linux. I wonder what computer languages are easy to grasp to create man - machine interactive interface software, which can accept inputs (parameters) from usrers, and present (display) the calculation results to users. Before, I have heared about Perl,... (10 Replies)
Discussion started by: cy163
10 Replies

8. Shell Programming and Scripting

launch & monitor process on remote host

Hi, I am working on HPUX11 systems. I intend to achieve following: Need to write a shell script that will launch a program on remote UNIX machine. It will be gr8 if in addition, the remote process can be monitored using some feedback. I donno how to use rsh / ssh for this. (specifying... (1 Reply)
Discussion started by: mrx
1 Replies

9. HP-UX

HP-UX - how to create virtual interface

OS - HP-UX B.10.20 A 9000/777 Anyone know how to set up a virtual interface on HP-UX? I've looked quickly through docs.hp.com and searched this site. No luck. And my HP Guru is sleeping today. (4 Replies)
Discussion started by: thehoghunter
4 Replies
Login or Register to Ask a Question