Posts tagged shell

HP Array Configuration Utility RAID Controller Checker Script

2

hpacucli-check.sh is a bash shell script that checks the status of the logical drives on a HP Server with hpacu (HP Array Configuration Utility Client) installed, syslogging and sending an email with errors to administrators.

Tested ona HP Proliant DL580 G5 Server with Debian Lenny and HP Array Configuration Utility Installed, this software is available from the “HP ProLiant Support Pack CD for Debian GNU/Linux 5.0 (“lenny”) and Ubuntu 9.04 (“jaunty”) x86 and AMD64/EM64T” downloadable from the HP Support Web Site.

http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=US&swItem=MTX-799829d8271f455d9367978b5a&prodTypeId=15351&prodSeriesId=1121516

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
 
###
# FILE: hpacucli-check.sh (2010-11-05)
# LICENCIA: GNU/GPL v3.0
# USAGE: Check the status of the logical drives on a HP Server 
#        with hpacu (HP Array Configuration Utility Client)
#        installed, syslog and send an email with errors.
# AUTHOR: Olaf Reitmaier Veracierta <olafrv@gmail.com> / www.olafrv.com
##
 
MAIL=root@localhost
HPACUCLI=`which hpacucli`
HPACUCLI_TMP=/tmp/hpacucli.log
 
hpacucli ctrl all show | grep "Slot " | while read line1
do
   slot=`expr match "$line1" '.*Slot \([0-9]\).*'`
   echo "Searching controller in slot #$slot..."
   hpacucli ctrl slot=$slot array all show | grep array | while read line2
   do
      array=`expr match "$line2" '.*array \([a-Z]\).*'`
      echo "Searching array $array..."
      hpacucli ctrl slot=$slot array $array logicaldrive all show | grep logicaldrive | while read line3
      do
         logicaldrive=`expr match "$line3" '.*logicaldrive \([0-9]\).*'`
         echo "Searching logical drive #$logicaldrive..."
         if [ `hpacucli ctrl slot=$slot array $array logicaldrive $logicaldrive show | grep "Status: OK$" | wc -l` -lt 2 ]
         then
            msg="RAID Controller Error Slot #$slot Array $array Logical Drive #$logicaldrive"
            echo $msg
            logger -p syslog.error -t RAID "$msg"
            $HPACUCLI ctrl slot=$slot show config detail > $HPACUCLI_TMP
            mail -s "$HOSTNAME [ERROR] - $msg" "$MAIL" < $HPACUCLI_TMP
            rm -f $HPACUCLI_TMP
         fi
      done
   done
done

See Also: http://wiki.debian.org/HP/ProLiant

How to capitalize letters on bash shell script

1

It’s easy just use the tr command to lower, upper or capital case.

Here is an example…

1
2
3
4
5
6
7
8
9
function toCapital
{
   for x in $*
   do
      echo -n ${x:0:1} | tr '[a-z]' '[A-Z]' | xargs echo -n
      echo -n ${x:1} | tr '[A-Z]' '[a-z]' | xargs echo -n
      echo -n " "
   done
}

To test the function just call it:

1
toCapital yuCa aMigo

The output is:

Yuca Amigo

Hope it’s useful.

Shell Script para cambiar de pasarela de Internet

0

Shell Script para cambiar de pasarela de Internet

El Problema

Cómo cambiar automáticamente de puerta de enlace (pasarela) sin tener que reconfigurar cada estación de trabajo en una red local (LAN) con dos accesos a Internet.



Solución

1. Instalar y configurar el demonio cron, editar el /etc/crontab para que ejecute cada minuto un scripts de comprobación y cambio atuomático de la puerta de enlace así:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=”"
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
* * * * * root /root/switch-gw.sh

2. Luego ejecutar el comando chkconfig crond on

3. Finalmente ejecutar:
$ touch /root/switch-gw.sh
$ chmod 755 /root/switch-gw.sh

4. El contenido del archivo switch-gw.sh es el siguiente:

#!/bin/bash

#External direction to Internet
INTERNET=200.44.32.12

#Router ASDL
GW_ASDL=10.200.1.70

#Firewall Cisco PIX 506
GW_FR=129.1.1.69

#The result of one pinging
PING=0

#USE: change the default GW
#PARAM: $1 the new ip address
# $2 the new device for the ip address
#RETURN: none
function fswitch(){
echo “Switching…”
new_ip=$1
new_dev=$2
default_ip=`route | grep “default” | awk ‘{print $2}’`
default_dev=`route | grep “default” | awk ‘{print $8}’`
if [ "$new_ip" != "$default_ip" ]; then
route add -net 0.0.0.0/0 gw $new_ip dev $new_dev
route del -net 0.0.0.0/0 gw $default_ip dev $default_dev
fi
}

# USE: Ping to a host
# PARAM: $1 the host name
# RETURN: “0″ or “1″
function fping(){
ATTEMPS=3
PING=`ping -c$ATTEMPS $1 | grep ” 0% packet loss” | wc -l`
}

#Get the ip address of the gateway (gw)
#that you specified gateway in the arguments
if [ "$1" = "aba" ]; then
#is the first gw?
gw=$GW_ASDL
dev=”eth1″
else
if [ "$1" = "fr" ]; then
#is the second gw?
gw=$GW_FR
dev=”eth0″
else
#not found?, then get the actual default gateway.
gw=`route | grep “default” | awk ‘{print $2}’`
dev=`route | grep “default” | awk ‘{print $8}’`
fi
fi

#Testing ping to internet
fping $INTERNET

#Change the gateway if the current is not active
if [ "$PING" = "1" ] &&amp;amp; [ -z $1 ]; then
echo “Ping is OK, then no switching needed.”
else
#If no force then change to a new gateway
if [ "$2" = "force" ]; then
fswitch $gw $dev
echo “I’m forcing the switch to GW $gw on DEV $dev”
else
#Change to ASDL if default gateway is empty
echo “I’m trying to select an alternative gateway”
if [ -z "$1" ]; then
if [ "$gw" = "$GW_ASDL" ]; then
gw=$GW_FR
dev=”eth0″
else
gw=$GW_ASDL
dev=”eth1″
fi
fi
echo “Now I’m going to switch to GW $gw on DEV $dev”
fswitch $gw $dev
fi
fi

Go to Top
?>