Link to home
Start Free TrialLog in
Avatar of rdashokraj
rdashokraj

asked on

Perl script help

Hello,
I have a couple of requirements using Perl or Bash scripts. Please look at this command output given in the Code text box:

I want a script which will send me a mail, when anyone of the following incident occur:

1. when the command "netstat -an | grep 1530" fails to get the LISTEN value in its output.
2. In the output of /proc/net/bonding/bond0 file, when the value of "MII Status" is showing as "down".

An example at which the mail has to be sent:

[root@orasmb ~]# netstat -an | grep 1530
[root@orasmb ~]#                                                          <-- No output
[root@orasmb ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth4
Currently Active Slave: eth4
MII Status: up                                            
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: down                <-- Showing down, mail has to be sent now.                                
Link Failure Count: 1
Permanent HW addr: 00:15:17:97:b1:d9

Slave Interface: eth4
MII Status: up                                                    
Link Failure Count: 1
Permanent HW addr: 00:1a:64:db:34:58
[root@orasmb ~]#

In addition, in the Subject of the mail, it should contain the hostname of the server.

Thanks,
AR
[root@orasmb ~]# netstat -an | grep 1530
tcp        0      0 10.20.40.50:1530            0.0.0.0:*                           LISTEN                    <-----
tcp        0      0 10.20.40.50:1530            10.20.40.50:32964           TIME_WAIT
tcp        0      0 10.20.40.50:1530            10.20.40.50:32963           TIME_WAIT
tcp        0      0 10.20.40.50:1530            10.20.40.50:32969           TIME_WAIT
tcp        0      0 10.20.40.50:1530            10.20.40.50:32970           TIME_WAIT
 
[root@orasmb ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)
 
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth4
Currently Active Slave: eth4
MII Status: up                                            <-------------
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
 
Slave Interface: eth0
MII Status: up                                                <-------------
Link Failure Count: 1
Permanent HW addr: 00:15:17:97:b1:d9
 
Slave Interface: eth4
MII Status: up                                                    <-------------
Link Failure Count: 1
Permanent HW addr: 00:1a:64:db:34:58
[root@orasmb ~]#

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rchi54
rchi54
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rdashokraj
rdashokraj

ASKER

Thankyou all !