Daily health check script

Hi

I am still learning how to write shell scripts, so I started to write a script like this:

#!/bin/sh
date 
echo
outputOK () {
  echo $1 "[ ok ]"
}

outputOK () {
  echo $1 "[ warning ]"
}

for vol in `/usr/bin/grep -E 'hfs|vxfs|nfs|cifs' /etc/fstab | egrep -v '^#' | awk '{ print $3 }'`
do
if bdf    $vol | grep $vol > /dev/null
then
 outputOK "Filesystem: $vol    mounted"
 else    outputW  "Filesystem: $vol    NOT MOUNTED"
fi
done

But when I run, I got the following:

bdf: vxfs: No such file or directory
Filesystem: vxfs NOT MOUNTED [ Warning ]

Can you help

FR

Hi,

You are aware that bdf is a HPUX command, are you sure that that is the platform? Also it would seem that the output is expecting to see a Veritas volume.

Regards

Dave

Plaase post what Operating System and version and what Shell this is.

If this is HP-UX, the 3rd field in /etc/fstab is the filesystem type (e.g. vxfs). The second field is the filesystem mountpoint.

If I wanted to know which filesystems were mounted, I'd use the mount command (without any parameters).

The O.S. is hp-ux, that is why I use bdf:

#uname -a
HP-UX prep03 B.11.31 U ia64 3933449231 unlimited-user license

---------- Post updated 16-08-12 at 08:44 AM ---------- Previous update was 15-08-12 at 10:18 AM ----------

Any ideas on this?

Please help

Then main fault in your script is that the awk is extracting field 3 not field 2 from /etc/vfstab .

1 Like

Hi

Thanks a lot, it worked now:

#./daily_check
Fri Aug 17 17:46:08 SAST 2012

Filesystem: / mounted [ OK ]
Filesystem: /stand mounted [ OK ]
Filesystem: /tmp mounted [ OK ]
Filesystem: /home mounted [ OK ]
Filesystem: /opt mounted [ OK ]
Filesystem: /usr mounted [ OK ]
Filesystem: /var mounted [ OK ]
prep03[171]/tmp/fr #

I will try and add more commands

Hi

I am trying to use a modified code to check for lan, disk but with no success, please can you give me some hints:

#check if NIC cards are OK

if [ `ioscan -fnC lan |wc -l` != 1 ]
then
 if [ `ioscan -fnC lan  |grep CLAIMED|wc -l` != `ioscan -fnC lan |grep NO_HW|wc -l` ]
then
 outputW "Ethernet: Offline NICs detected."
else
 outputOK "Ethernet: All NICs are online"
fi
else
 outputOK "Ethernet: No NICs found."
fi

# check if Disks are OK

if [ `ioscan -fnC disk |wc -l` != 1 ]
then
 if [ `ioscan -fnC disk |grep CLAIMED|wc -l` != `ioscan -fnC disk |grep NO_HW|wc -l` ]
then
 outputW "Disks: Not CLAIMED disks detected."
else
 outputOK "Disks: All Disks are CLAIMED"
fi
else
 outputOK "Disks: No Disks found."
fi

and the output I am getting is:

Ethernet: Offline NICs detected. [ Warning ]


SAN: Offline HBAs detected. [ Warning ]


Disks: Not CLAIMED disks detected. [ Warning ]

and if I do ioscan:

prep03[133]/tmp/fr #ioscan -fnC lan
Class     I  H/W Path  Driver S/W State   H/W Type     Description
===================================================================
lan       0  0/1/1/0   igelan   CLAIMED     INTERFACE    HP PCI-X 1000Mbps Dual-port Built-in
lan       1  0/1/1/1   igelan   CLAIMED     INTERFACE    HP PCI-X 1000Mbps Dual-port Built-in
lan       2  0/2/2/0   igelan   CLAIMED     INTERFACE    HP PCI-X 1000Mbps Dual-port Built-in
lan       3  0/2/2/1   igelan   CLAIMED     INTERFACE    HP PCI-X 1000Mbps Dual-port Built-in
prep03[134]/tmp/fr #nwmgr

Name/          Interface Station          Sub-   Interface      Related
ClassInstance  State     Address        system   Type           Interface
============== ========= ============== ======== ============== =========
lan2           UP        0x78E7D1723F0E igelan   1000Base-SX
lan0           DOWN      0x78E7D1723F0C igelan   1000Base-SX
lan1           DOWN      0x78E7D1723F0D igelan   1000Base-SX
lan3           UP        0x78E7D1723F0F igelan   1000Base-SX
lan900         DOWN      0x000000000000 hp_apa   hp_apa
lan901         DOWN      0x000000000000 hp_apa   hp_apa
lan902         DOWN      0x000000000000 hp_apa   hp_apa
lan903         DOWN      0x000000000000 hp_apa   hp_apa
lan904         DOWN      0x000000000000 hp_apa   hp_apa
prep03[135]/tmp/fr #ioscan -fnC fc
Class     I  H/W Path     Driver S/W State   H/W Type     Description
====================================================================
fc        0  0/3/0/0/0/0  fclp   CLAIMED     INTERFACE    HP 403621-B21 4Gb PCIe 2-port LPe1105 FC Mezzanine Adapter
                         /dev/fclp0
fc        1  0/3/0/0/0/1  fclp   CLAIMED     INTERFACE    HP 403621-B21 4Gb PCIe 2-port LPe1105 FC Mezzanine Adapter
                         /dev/fclp1
prep03[136]/tmp/fr #ioscan -fnC disk
Class     I  H/W Path  Driver S/W State   H/W Type     Description
==================================================================
disk      0  0/2/1/0.0.0.0.0  sdisk   CLAIMED     DEVICE       HP      IR Volume
                      /dev/dsk/c0t0d0     /dev/dsk/c0t0d0s2   /dev/rdsk/c0t0d0    /dev/rdsk/c0t0d0s2
                      /dev/dsk/c0t0d0s1   /dev/dsk/c0t0d0s3   /dev/rdsk/c0t0d0s1  /dev/rdsk/c0t0d0s3
prep03[137]/tmp/fr #

Please can you help

Let's pick one of the tests and assume that OutputW and OutputOK are other scripts or local functions.

There is a basic logic error here. The main condition does not work unless perhaps there is only ever one disk on a HP-UX system! Not sure about the syntax either.
We should run ioscan only once because it is a very powerful program and can cause the view to change. Be aware that running ioscan can cause dead hardware to completely disappear from the inventory (and therefore not show as NO_HW).
Let's try something lke this (untested and purely to demonstrate logic and not recommended).

ioscan -fnC disk > /tmp/ioscan_fnC_disk # Store output from ioscan
total_count=$(egrep "CLAIMED|NO_HW" ioscan_fnC_disk|wc -l)
dead_count=$(grep "NO_HW" ioscan_fnC_disk|wc -l)
if [ ${total_count} -eq  0 ]
then
        outputW "Disks: No Disks found."
else
        if [ ${dead_count} -gt 0 ]
        then
              outputW "Disks: Not CLAIMED disks detected."
        else
              outputOK "Disks: All Disks are CLAIMED"
        fi
fi
rm -f ioscan_fnC_disk # Clean up workfile

On my systems I run ioscan -fn (i.e. all hardware) daily and compare this output with the output from the same command yesterday. No attempt to predict every possible error output from ioscan. If there are differences, this is reported as a major error. Obviously if you detect a failure and repair it you will get one false alert for the broken hardware re-appearing.
I started doing this after discovering that a major hardware failure can cause a crash and reboot during which the dead hardware can completely and silently disappear from the ioscan inventory.
That reminds me. Don't forget to have a script to read the syslog and identify anything abnormal (and I don't mean broken printers).

1 Like