Skip to content

How To: Report on OS Status Script

cpx April 14, 2008 6 min read GNU/Linux
Status #!/bin/bash MY_VERSION="1.22k" # status_report.sh - Generate a status report about a Linux machine # # Last update: July 15, 2008 # (C) Copyright 2005-2008 by Arno van Amersfoort # Homepage              : http://rocky.eld.leidenuniv.nl/ # Email                 : a r n o v a AT r o c k y DOT e l d DOT l e i d e n u n i v DOT n l #                         (note: you must remove all spaces and substitute the @ and the . at the proper locations!) # ---------------------------------------------------------------------------------------------------------------------- # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. # ---------------------------------------------------------------------------------------------------------------------- # Set path PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin # Specify custom (source) script, if used CUSTOM_SCRIPT="/usr/local/sbin/sr_custom_script" echo "$(date +'%b %d %k:%M:%S') Status report v$MY_VERSION for $HOSTNAME" echo "Written by Arno van Amersfoort" echo "--------------------------------------------------" uname -a free -m uptime export TERM=vt100; /usr/bin/top -b -n 1 |grep -i '^CPU' if [ -e /proc/mdstat ]; then echo "" echo "---------------" echo "| RAID status |" echo "---------------" #  if [ -x /sbin/mdadm ]; then #    /sbin/mdadm --detail --scan 2>&1 #    echo "" #  fi FAIL=0 DEGRADED=0 MISMATCH=0 unset IFS while read LINE; do printf "%s" "$LINE" if echo "$LINE" |grep -q 'active raid'; then DEV="$(echo "$LINE" |awk '{ print $1 }')" printf " (mismatch_cnt=%s)" "$(cat /sys/block/$DEV/md/mismatch_cnt)" # NOTE: Mismatch fixing (repair) doesn't work yet with a 2.6.18 kernel! if [ "$(cat /sys/block/$DEV/md/mismatch_cnt)" != "0" ]; then MISMATCH=$(($MISMATCH +1)) #        printf " (WARNING: Unsynchronised (mismatch) blocks!)" fi if echo "$LINE" |grep -q '\(F\)'; then FAIL=$(($FAIL + 1)) printf " (WARNING: FAILED DISK(S)!)" fi if echo "$LINE" |grep -q '\(S\)'; then printf " (Hotspare(s) available)" else printf " (NOTE: No hotspare?!)" fi fi if echo "$LINE" |grep -q 'blocks'; then if echo "$LINE" |grep -q '_'; then DEGRADED=$(($DEGRADED + 1)) printf " (DEGRADED!!!)" fi fi echo "" done < /proc/mdstat if [ $FAIL -gt 0 ]; then echo "" echo "** WARNING: $FAIL MD(RAID) array(s) have FAILED disk(s)! **" fi if [ $DEGRADED -gt 0 ]; then echo "" echo "** WARNING: $DEGRADED MD(RAID) array(s) are running in degraded mode! **" fi if [ $MISMATCH -gt 0 ]; then echo "" echo "** WARNING: $MISMATCH MD(RAID) array(s) have unsynchronized (mismatch) blocks! **" fi fi echo "" echo "---------------------" echo "| S.M.A.R.T. status |" echo "---------------------" if which smartctl 2>&1 >/dev/null; then cat /proc/partitions |grep -e "sd.$" -e "sd. " -e "hd.$" -e "hd. " |awk '{ print $4 }' |while read HDD; do #    printf "/dev/$HDD: " printf "/dev/%s: " "$HDD" # Explicity turn on SMART on device: smartctl -q silent -s on /dev/$HDD #    smartctl -H -l error /dev/$HDD |tail -n5 |grep -v -e "^$" -e "Version" -e "Device does not support" -e "Enable Save with" 2>&1 smartctl -H /dev/$HDD |grep -v -e '^$' |tail -n1 2>&1 done else echo "smartctl binary not found (smartmontools not installed?)" fi #echo "" #echo "---------------------" #echo "| S.M.A.R.T. status |" #echo "---------------------" #if which ide-smart 2>&1 >/dev/null; then #  cat /proc/partitions |grep -e "sd.$" -e "sd. " -e "hd.$" -e "hd. " |awk '{ print $4 }' |while read HDD; do ##    printf "/dev/$HDD: " #    printf "/dev/%s: " "$HDD" #    # Explicity turn on SMART on device: #    ide-smart -q  -1 /dev/$HDD ##    smartctl -H -l error /dev/$HDD |tail -n5 |grep -v -e "^$" -e "Version" -e "Device does not support" -e "Enable Save with"$ #    ide-smart -H /dev/$HDD |grep -v -e '^$' |tail -n1 2>&1 #  done #else #  echo "smartctl binary not found (smartmontools not installed?)" #fi echo "" echo "------------------" echo "| DiskSpace info |" echo "------------------" DF_WARNING=0 IFS=$'\n' for LINE in `df -h -P -l -T --sync`; do #  echo -n "$LINE" printf "%s" "$LINE" if echo "$LINE" |grep -q -v "Use%"; then free_perc=`echo "$LINE" |awk '{ print $6 }' |sed s,'%',,` if [ $free_perc -gt 95 ]; then echo ' (At or near max. capacity!)' DF_WARNING=1 fi fi echo "" done if [ "$DF_WARNING" = "1" ]; then echo "" echo "** WARNING: One or more filesystems are at or near maximum capacity! **" fi if [ -d /var/log/fsck ]; then echo "" echo "------------------" echo "| Fsck boot logs |" echo "------------------" cat /var/log/fsck/* fi echo "" echo "--------------------" echo "| Hardware sensors |" echo "--------------------" if which sensors 2>&1 >/dev/null; then # Re-read configuration: if [ -n "$(sensors -s 2>&1)" ]; then echo "** WARNING: Unable to read hardware sensors (/etc/sensors.conf incorrect/missing?) **" else result=`sensors 2>&1` echo "$result" if echo "$result" |grep -q "ALARM"; then echo "" echo "** WARNING: One or more sensors show ALARM! **" fi fi else echo "sensors binary not found (lm-sensors not installed?)" fi echo "" echo "------------------------------------" echo "| Display listening server sockets |" echo "------------------------------------" if which netstat 2>&1 >/dev/null; then netstat -nal |egrep '^tcp' | sed -r 's/[ ]+/ /g' | cut -d ' ' -f 1,6 | sort | uniq -c | sort -rn else echo "no netstat found" fi echo "" echo "-----------------------" echo "| Kernel warnings log |" echo "-----------------------" KERNEL_LOG="current" if [ ! -f "/var/log/kernel/$KERNEL_LOG" ]; then echo "/var/log/kernel/$KERNEL_LOG does NOT exist. Consider adding a line like" echo "'kern.warn    /var/log/kernel/$KERNEL_LOG' to your syslog.conf" else cat "/var/log/kernel/$KERNEL_LOG.0" >"/tmp/$KERNEL_LOG" 2>/dev/null cat "/var/log/kernel/$KERNEL_LOG" >>"/tmp/$KERNEL_LOG" filesize=$(ls -l "/tmp/$KERNEL_LOG" |awk '{ print $5 }') if [ $filesize -eq 0 ]; then echo "(Empty)" else cat "/tmp/$KERNEL_LOG" fi # Remove temp file rm -f "/tmp/$KERNEL_LOG" # Remove log files rm -f "/var/log/kernel/$KERNEL_LOG.1" 2>/dev/null mv "/var/log/kernel/$KERNEL_LOG.0" "/var/log/$KERNEL_LOG.1" 2>/dev/null mv "/var/log/kernel/$KERNEL_LOG" "/var/log/$KERNEL_LOG.0" 2>/dev/null printf "" >|"/var/log/$KERNEL_LOG" fi echo "" echo "----------------------------" echo "| Available Debian Updates |" echo "----------------------------" if which apt-get 2>&1 >/dev/null; then apt-get update -q=2 2>&1 echo "** Testing what packages could be upgraded: **" apt-get upgrade -u --download-only -y -q -V 2>&1 else echo "apt-get binary not found (apt-get not installed?)" fi echo "" echo "----------------------------" echo "| Available Gentoo Updates |" echo "----------------------------" if which emerge 2>&1 >/dev/null; then emerge --sync --quiet 2>&1 echo "** Testing what packages could be upgraded: **" emerge -DuNpv world 2>&1 else echo "emerge binary not found (emerge not installed?)" fi echo "" echo "-------------------------------------" echo "| Available Gentoo Security Updates |" echo "-------------------------------------" if which glsa-check 2>&1 >/dev/null; then echo "** Test if this system is affected by the given GLSA: **" glsa-check -t all 2>&1 else echo "glsa-check binary not found (glsa-check not installed?)" fi echo "" echo "-------------------" echo "| Chkrootkit info |" echo "-------------------" if which chkrootkit 2>&1 >/dev/null; then chkrootkit -q >/tmp/chkrootkit_output.txt 2>&1 if [ -n "$(cat /tmp/chkrootkit_output.txt)" ]; then cat /tmp/chkrootkit_output.txt else echo "Nothing found" fi rm -f /tmp/chkrootkit_output.txt else echo "chkrootkit binary not found (chkrootkit not installed?)" fi if which clamscan 2>&1 >/dev/null; then echo "" echo "-----------------" echo "| ClamAV status |" echo "-----------------" # Show clam version: clamscan --version 2>&1 # Dummy run to see whether we're not out-of-date: echo "" |clamscan --quiet - 2>&1 fi if [ -e /var/log/backup.log ]; then echo "" echo "---------------" echo "| Backup info |" echo "---------------" cat /var/log/backup.log fi if [ -e "$CUSTOM_SCRIPT" ]; then . "$CUSTOM_SCRIPT" fi # TODO?: Fix no smart disabled error (smartctl returns 0)

Be the first to comment

protected · no tracking

0 comments