Scripts
20091229: find_controller.sh
by dervish on Dec.29, 2009, under Scripts
#!/bin/sh # # Created: 20091229 Jamey Hopkins # Find PCI controller and output matches into $STR.servers # 20100406 jah - added ping check if [ "$1" = "" ] then echo "Please pass a search string." echo "Example: find_controller.sh AAC-RAID" exit else STR="$1" fi >$STR.servers for SERVER in `cat linux.servers` do echo -n $SERVER MSG="Controller not found." ping -c1 $SERVER >/dev/null 2>&1 if [ $? -eq 0 ] then DATA=`ssh $SERVER sudo /sbin/lspci 2>/dev/null | grep $STR` [ "$DATA" != "" ] && MSG="Controller: $DATA" [ "$DATA" != "" ] && echo $SERVER >>$STR.servers # echo what we found echo -e "\t$MSG" else echo -e "\tServer not reachable." fi done
20091222: raidcheck.sh
by dervish on Dec.22, 2009, under Scripts
#!/bin/bash
# raidcheck.sh – search for SAS1064 or Adaptec AAC-RAID controller and report failed drives
#
# Created 20091222 Jamey Hopkins
# Note: replaced by 20110511: raidcheck.sh
process_mpt-status() {
ID=`grep Found status.0 | cut -f2 -d= | cut -f1 -d,`
/usr/sbin/mpt-status -i $ID -s >status.1
C1=`cat status.1 | grep phys_id | wc -l`
C2=`cat status.1 | grep phys_id | grep ONLINE | wc -l`
[ “$C1” = “0” ] && echo “No Drives Found”
[ “$C1” = “$C2” ] && echo “$C2 of $C1 Drives Are Online”
#echo “Controller ID=$ID”
if [ $C2 -lt $C1 ]
then
echo “ERROR: Failed SAS Drive Found”
echo “$C2 of $C1 Drives Are ONLINE”
echo
exit 2
fi
}
AACRAID=”0″;SAS1064=”0″
# search for SAS1064 controller
DATA=`/sbin/lspci | grep SAS1064 2>/dev/null`
if [ “$DATA” != “” ]
then
#echo Process SAS
SAS1064=”1″
# check if mptctl module is loaded
MPT=`/sbin/lsmod | grep mptctl 2>/dev/null`
[ ! -n “$MPT” ] && echo “mptctl module not loaded”
/usr/sbin/mpt-status -p >status.0 2>&1
grep “not found” status.0 >/dev/null
if [ “$?” = “0” -a ! -n “$MPT” ]
then
echo “mpt-status not found in /usr/sbin”
else
process_mpt-status
fi
fi
# search for Adaptec AAC-RAID controller
DATA=`/sbin/lspci | grep AAC-RAID 2>/dev/null`
if [ “$DATA” != “” ]
then
#echo Process AAC-RAID
AACRAID=”1″
STATE=`/usr/StorMan/arcconf getconfig 1 | grep “Logical devices/Failed/Degraded” | cut -f2 -d: | xargs echo`
#echo state is -${STATE}-
if [ “$STATE” != “1/0/0” ]
then
echo ERROR: AAC-RAID Failed Drive Found
echo
exit 2
else
echo “AAC-RAID: No failed or degraded drives found.”
fi
fi
if [ $SAS1064 = 0 -a $AACRAID = 0 ]
then
echo “No controllers found.”
fi
rm status.0 status.1 >/dev/null 2>&1
exit 0
BASH: createsftpaccount.sh
by dervish on Mar.04, 2009, under Linux, Scripts
|
20060425: dacprobe
by dervish on Apr.25, 2006, under AIX, Linux, Scripts
#!/bin/sh
# dacprobe - monitor/audit daemon (drive space and rootkits)
# 20040830 - created by jamey hopkins
#
# 20050425 jah - added -x option to ssh command in order to speed up ssh call
# 20050811 jah - added SSH fail notice
# 20060425 jah - use -P on linux df to prevent drive space being placed on second line
# shows up on servers with logical volumes
# spaces at start/end required
TEST=" lenxintq1 tto xto tlv qlv qto xlv "
PROD=" cvs dacadmin dacbup1 dacedip1 dacxextp1 dlv dms dto dxr fax1 fax2 ibb ibmtransp1 ibmxextp1 icc imserv1 lencextp1 lencometp1 lenpsp1 lentransp1 lenxintp1 ncc ns1 ns2 ticket toshcometp1 "
ALL="$PROD $TEST"
DLIMIT=90
MAILA="user@server.com"
MAILB="user@server.com pager@myairmail.com"
# check drive space
echo
echo -n "Checking Disk Space->"
echo >space.list
for HOST in `echo $ALL`
do
echo -n " $HOST"
if [ "$HOST" = "dacedip1" -o "$HOST" = "lenpsp1" ]
then
ssh -x $HOST df -k >dacprobe.$$ 2>/dev/null
[ $? -ne 0 ] && FAIL="$FAIL $HOST"
else
ssh -x $HOST df -P >dacprobe.$$ 2>/dev/null
[ $? -ne 0 ] && FAIL="$FAIL $HOST"
fi
COUNT=`cat dacprobe.$$ | wc -l | xargs echo`
COUNT=`expr $COUNT - 1`
cat dacprobe.$$ | tail -$COUNT >temp.$$ 2>/dev/null
cat temp.$$ | grep -v cdrom >dacprobe.$$
while read LINE
do
PERCENT=`echo $LINE | awk '{ print $5 }'`
# redo PERCENT var if host is AIX
[ "$HOST" = "lenpsp1" ] && PERCENT=`echo $LINE | awk '{ print $4 }'`
PERCENT=`echo $PERCENT | sed 's/%//g'`
if [ $PERCENT -gt $DLIMIT ]
then
PART=`echo $LINE | awk '{ print $6 }'`
# redo PART var if host is AIX
[ "$HOST" = "lenpsp1" ] && PART=`echo $LINE | awk '{ print $7 }'`
HCAPS=`echo $HOST | tr [a-z] [A-Z]`
echo "${HCAPS}'s Partition $PART is ${PERCENT}% Full" >> space.list
[ "$EMAIL" != "$MAILB" ] && EMAIL=$MAILA
# page if a prod server and > 98 percent full
echo $PROD | grep $HOST >/dev/null 2>&1
[ $? -eq 0 -a $PERCENT -gt 98 ] && EMAIL=$MAILB
fi
done > space.list
echo "WARNING - Drive Space Check Failed on the Following Servers:" >>space.list
echo "$FAIL" >>space.list
echo >> space.list
echo "Please make sure dacprobe account exists and the SSH exchanges happen auto magically." >> space.list
echo "If server is permanently down, then remove it from the list of servers to monitor." >> space.list
fi
if [ -s space.list ]
then
echo
cat space.list
{
echo "subject: Drive Partition Exceeds ${DLIMIT}% Full Limit"
echo "Partition Information:"
cat space.list
echo
echo "Servers Checked:"
echo "P:$PROD"
echo "T:$TEST"
} | /usr/sbin/sendmail -ONoRecipientAction=add-to -fdacprobe -oi "$EMAIL"
fi
rm space.list
echo
################ gather up chkrootkit output files and email
echo -n "Gather and Mail CHKROOTKIT Reports->"
PROD=" dlv dms dxr ibmpsp1 lenpsp1 lenxintp1 dacxextp1 dacxextq1 "
rm /tmp/chkrootkit.mailfile >/dev/null 2>&1
for HOST in `echo $PROD`
do
echo -n " $HOST"
ssh -x $HOST "cat /tmp/chkrootkit.status.*" >>/tmp/chkrootkit.mailfile 2>/dev/null
done
{
echo "subject: CHKROOTKIT Status Report"
echo
echo "Servers Checked:"
echo "P:$PROD"
echo
echo "Server Reports Returned:"
cat /tmp/chkrootkit.mailfile 2>/dev/null
} | /usr/sbin/sendmail -ONoRecipientAction=add-to -fdacprobe -oi "$EMAIL"
echo
echo
20040728: si (System Information)
by dervish on Jul.28, 2004, under Linux, Scripts
#!/bin/sh
# System Information for Linux/SCO Openserver
# Created: 07 April 2000
# by: Jamey Hopkins
#
# 23July2002 jah - send error on uptime and ps to /dev/null to handle
# output of unknown HZ value linux kernel bug
# 28July2004 jah - added CPU information / format change
#
OS=`uname`
CPU=`cat /proc/cpuinfo | grep "model name" | tail -1 | awk -F: '{ print $2 }' | xargs echo`
NCPU=`cat /proc/cpuinfo | grep "processor" | wc -l | xargs echo`
MHZ=`cat /proc/cpuinfo | grep "MHz" | tail -1 | awk -F: '{ print $2 }' | xargs echo`
echo
echo [ `uname -n | tr a-z A-Z` ]
date
printf "%s on %s %s (%s MHz)\n" "$OS" "$NCPU" "$CPU" "$MHZ"
STATS=`uptime 2>/dev/null`
echo $STATS
echo
echo "Active Processes Using >= 1% of CPU:"
echo _________________________________________________________
if [ "$OS" = "Linux" ]
then
ps -e -o user -o pid -o c -o args 2>/dev/null | grep -v ' 0 '
elif [ "$OS" = "SCO_SV" ]
then
ps -A -o user -o pid -o c -o args 2>/dev/null | grep -v ' 0 ' \
| grep -v $$ > /tmp/ps.tmp
echo "UID\\t\\tPID\\tC\\tCMD"
while read data
do
set $data
if [ $3 -gt 4 ]
then
echo -n $1\\t
if [ `expr length $1` -lt 8 ]
then echo -n \\t
fi
echo $2\\t$3\\t$4' '$5
fi
done < /tmp/ps.tmp
fi
echo _________________________________________________________
rm /tmp/si.tmp /tmp/usr.tmp /tmp/ps.tmp >/dev/null 2>&1
echo