ciphermethod.com

Scripts

20130530: si

by on May.30, 2013, under AIX, Linux, Scripts, Solaris, Sun


#!/bin/sh
# System Information
# Created: 07 April 2000
# by: Jamey Hopkins
#
# 23Jul2002 jah - send error on uptime and ps to /dev/null to handle
# output of unknown HZ value kernel bug
# 28Jul2004 jah - added CPU information / format change
# 26Apr2013 jah - added SunOS support
# 21May2013 jah - initial linux distro support (redhat mint oracle ubuntu)
# 30May2013 jah - added AIX support

OS=`uname`

echo
echo [ `uname -n` ]
date
if [ "$OS" = "Linux" ]
then
DISTRO=`lsb_release -d | cut -f2 -d: | xargs echo`
RH=`cat /proc/version 2>/dev/null | grep redhat.com`
[ "$RH" ] && DISTRO=`cat /etc/redhat-release`
OR=`cat /proc/version 2>/dev/null | grep oracle`
[ "$OR" ] && DISTRO="(Oracle) `cat /etc/enterprise-release`"
[ "$DISTRO" = "" ] && DISTRO="Unknown Distro"
echo $DISTRO

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`
printf "%s on %s %s (%s MHz)\n" "$OS" "$NCPU" "$CPU" "$MHZ"
fi

if [ "$OS" = "SunOS" ]
then
CPU=`/usr/sbin/psrinfo -v | grep "processor operates" | head -1 | awk '{ print $2 }'`
NCPU=`/usr/sbin/psrinfo -v | grep Status | wc -l | xargs echo`
REL=`uname -X | grep Release | cut -f3 -d' '`
MHZ=`/usr/sbin/psrinfo -v | grep "operates at" | head -1 | awk '{ print $6" "$7 }' | sed 's/,//g'`
printf "%s %s on %s %s (%s)\n" "$OS" "$REL" "$NCPU" "$CPU" "$MHZ"
fi

if [ "$OS" = "AIX" ]
then
CPU=`lsattr -E -l proc0 | grep "Processor type" | awk '{ print $2 }'`
NCPU=`lscfg | grep proc | wc -l | xargs echo`
REL=`oslevel`
MHZ=`pmcycles | awk '{ print $5" "$6 }'`
printf "%s %s on %s %s (%s)\n" "$OS" "$REL" "$NCPU" "$CPU" "$MHZ"
fi

STATS=`uptime 2>/dev/null`
echo $STATS

echo
echo "Active Processes Using >= 1% of CPU:"
echo _________________________________________________________

if [ "$OS" = "Linux" -o "$OS" = "SunOS" ]
then
ps -e -o user -o pid -o c -o args 2>/dev/null | grep -v ' 0 '
elif [ "$OS" = "AIX" ]
then
ps -e -o user -o pid -o cpu -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

Leave a Comment more...

reload.sh: Cron Script to Reshuffle SHOUTcast Playlist

by on Nov.16, 2012, under Linux, Scripts



#!/bin/sh
# Perform kill -USR1 on running sc_trans
# Use in nightly cron to reshuffle "random" playlist
# 20121116 - Jamey Hopkins
 
# Note: sc_trans accepts the following signals:
# HUP - flush logfiles (close and reopen) -- will make console logging stop
# WINCH - jump to next song
# USR1 - reload playlist off disk (will not interrupt current playing stream)
# USR2 - toggle shuffle on/off
# TERM - normal sc_trans shutdown (clean)
 
ID=`ps -ef | grep sc_trans | grep -v grep |awk '{ print $2 }'`
 
if [ "$ID" ]
then
  echo "Reloading playlist for sc_trans at $ID"
  kill -USR1 $ID
else
  echo "Did not find a running sc_trans"
fi


Leave a Comment more...

rocheck.sh

by on Nov.17, 2011, under Scripts

#!/bin/sh

# Created 20111107 – Jamey Hopkins
# Nagios script to check base file paths for a possible read only filesystem condition

USER=`whoami`
F=”rocheck.safetodelete”
# sets paths to test
PATHS=`df -P -l -x tmpfs -x vmhgfs -x iso9660 | column -t | awk ‘{ print $6 }’ | grep -v “Mounted” | xargs echo`
# define specific paths
#PATHS=”/ /home /opt /tmp /usr /var”

if [ “$USER” != “root” ]
then
   echo “Run $0 command as root”
   exit
fi

for P in `echo $PATHS`
do
   [ “$P” = “/” ] && P=”” # don’t process a double slash
   PF=”$P/$F”
   touch $PF >/dev/null 2>&1
   if [ “$?” != “0” ]
   then
      [ “$P” = “” ] && P=”/” # add slash back if it was ro
      FAIL=”$FAIL $P” # add P to string of failed paths
   fi
   [ -e $PF ] && rm $PF >/dev/null 2>&1
done

if [ “$FAIL” != “” ]
then
   # return an error 2 status with a list of directories that failed the touch test
   echo “Read Only:$FAIL”
   exit 2
fi

# return a good status with the list of directories that were checked
echo “Good: $PATHS”
exit 0

Leave a Comment more...

changelin.sh

by on Jul.12, 2011, under Scripts

#!/bin/sh
# Change user password across a list of servers.
# 20100421 – Created by Jamey Hopkins
# 20110712 – Check if login exists before changing password
#            Exit if login or password is blank
#
# note:  be sure account.info gets removed from remote server if script is aborted
#

echo
echo “Change Users Linux/AIX Password”
echo

if [ “$1” = “” ]
then
  echo “Need server list.”
  echo “example: $0 servers.txt”
  echo
  exit
fi

if [ ! -f $1 ]
then
  echo “Server list $1 not found.”
  echo
  exit
fi

# list seems good, accept it
LIST=$1

echo -n “Enter users login: ”
read LOGIN

if [ “$LOGIN” = “” ]
then
  echo “user account can not be blank”
  echo
  exit
fi

echo “Enter new password”
echo -n “Password: ”
stty -echo
read PASS1
stty echo
echo
echo “Enter password again”
echo -n “Password: ”
stty -echo
read PASS2
stty echo

echo

if [ “$PASS1” != “$PASS2” ]
then
  echo “password mismatch”
  echo
  exit
fi

if [ “$PASS1” = “” ]
then
  echo “passwords can not be blank”
  echo
  exit
fi
echo “$LOGIN:$PASS1” >account.info

echo
# let’s roll
for X in `cat $LIST`
do
  echo “$X: setting new password for $LOGIN”
  VALID=`ssh $X “grep ^$LOGIN: /etc/passwd | cut -f1 -d:”`
  if [ $VALID ]
  then
     scp ./account.info $X: >/dev/null
     ssh $X “cat account.info | sudo /usr/sbin/chpasswd” >/dev/null
     # clean up password file (be sure to manually remove if script gets aborted)
     ssh $X rm account.info
  else
     echo “Account doesn’t exist.  Skipping….”
  fi
done

# clean up password file
rm account.info

echo

Leave a Comment more...

20110511: raidcheck.sh

by on May.11, 2011, under Scripts

#!/bin/bash

# raidcheck.sh – Search for SAS1064 or Adaptec AAC-RAID controller and report failed/degraded drives
#
# 20091222 jah – Created by Jamey Hopkins
# 20110511 jah – Added support for more than 1 drive. Still defaults to controller 1.
#                      rm UcliEvt.log
#                      Code/error message cleanup/clarification.

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}-
 #STATE=”1/0/1″  # Set STATE for Testing
 STATE2=`echo $STATE | cut -f2 -d’/’`
 STATE3=`echo $STATE | cut -f3 -d’/’`
 if [ “$STATE2” != “0” -o “$STATE3” != “0” ]
 then
  echo “ERROR: AAC-RAID Error – Devices/Failed/Degraded $STATE”
  echo
  exit 2
 else
  echo “AAC-RAID: No Failed or Degraded Drives Found.”
 fi
fi

if [ $SAS1064 = 0 -a $AACRAID = 0 ]
then
 echo “No supported controllers found.”
fi

rm status.0 status.1 >/dev/null 2>&1
rm UcliEvt.log >/dev/null 2>&1

exit 0

1 Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

But Wait, There's More!

A few highly recommended friends...