Simple configuration dump script for web servers

I build this script long ago, using another script for reference. Lost track of the original long ago, sorry if it was yours. Basically, I run this script daily on web servers along with a tar backup of the /etc and any other vital directories. In the event of a disaster it is much easier to recover with this information. This isn’t as important now that we use virtual machines for almost everything, but it has come in handy quite a few times.

I remember editing this a while back and not finishing the edit. So, if something isn’t working let me know and I will see if I can fix it.

Note: Cleaned it up a little bit, difficult to do on the phone. Probably screwed up the SQL syntax or something. Nothing destructive in here, so if I made a mistake it isn’t going to break anything.  I’ll take a closer look tomorrow and verify it still works.


#!/bin/bash
HOSTNM=$(hostname -s)
HOSTNMA=$(hostname -a)
NOW=$(date +"%m-%d-%Y")
RPTNM="serverinfo__"${HOSTNM}_${NOW}
HOSTNM=`hostname -s`
IP_ADDRS=`ifconfig | grep 'inet addr' | grep -v '255.0.0.0' | cut -f2 -d':' | awk '{print $1}'`
IP_ADDRS=`echo $IP_ADDRS | sed 's/\n//g'`
MEMORY=`free | grep Mem | awk '{print $2}'`
CPUS=`cat /proc/cpuinfo | grep processor | wc -l | awk '{print $1}'`
CPU_MHZ=`cat /proc/cpuinfo | grep MHz | tail -n1 | awk '{print $4}'`
CPU_TYPE=`cat /proc/cpuinfo | grep vendor_id | tail -n 1 | awk '{print $3}'`
CPU_TYPE2=`uname -m`
OS_NAME=`uname -s`
OS_KERNEL=`uname -r`
BOOT=$(last -x | grep wtmp | sed 's/wtmp begins //g')
UPTIME=`uptime | cut -f5-8 -d' '`
PCIINFO=`lspci | cut -f3 -d':'`
TODAYDT=$(date)
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo SERVER REVIEW >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo "Today's Date : $TODAYDT">> $RPTNM.log
echo "Hostname : $HOSTNM">> $RPTNM.log
echo "Hostname Alias : $HOSTNMA">> $RPTNM.log
echo "Host Address(es) : $IP_ADDRS">> $RPTNM.log
echo "Main Memory : $MEMORY">> $RPTNM.log
echo "Number of CPUs : $CPUS">> $RPTNM.log
echo "CPU Type : $CPU_TYPE $CPU_TYPE2 $CPU_MHZ MHz">> $RPTNM.log
echo "OS Name : $OS_NAME">> $RPTNM.log
echo "Kernel Version : $OS_KERNEL">> $RPTNM.log
echo "Bootup : $BOOT - Uptime $UPTIME">> $RPTNM.log
echo>> $RPTNM.log
echo "Devices">> $RPTNM.log
echo "----------------------------------">> $RPTNM.log
echo "$PCIINFO">> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Who is connected to the system >> ./$RPTNM.log
echo ------------------------------ >> $RPTNM.log
w >> $RPTNM.log 2>>$RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo List of usernames configured on the system >> ./$RPTNM.log
echo ----------------------------------------------------------- >> $RPTNM.log
cat /etc/passwd >> $RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo List of recent logins to system >> ./$RPTNM.log
echo ------------------------------->> $RPTNM.log
last -a >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo Linux release info >> $RPTNM.log
echo ------------------>> $RPTNM.log
lsb_release -a >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
head -n 1 /etc/issue >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Info about current Kernel version>> ./$RPTNM.log
echo --------------------------------- >> $RPTNM.log
uname -a >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo CPU Info >> $RPTNM.log
echo -------- >> $RPTNM.log
cat /proc/cpuinfo >> $RPTNM.log
echo >> $RPTNM.log
echo Disk free >> $RPTNM.log
echo ---------- >> $RPTNM.log
df -h >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Memory free >> $RPTNM.log
echo ------------ >> $RPTNM.log
free -m >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo LSPCI and LSUSB output, lists installed hardware on the system >> $RPTNM.log
echo -------------------------------------------------------------- >> $RPTNM.log
lspci >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
lsusb >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Disk mount tree >> $RPTNM.log
echo --------------- >> $RPTNM.log
findmnt -a >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
mount echo >> $RPTNM.log
echo >> $RPTNM.log
fdisk -l >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
cat /etc/fstab >> $RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Services running on the system, only those listed in init.d >> $RPTNM.log
echo >> $RPTNM.log
service --status-all >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Open ports and services attached to those ports >> $RPTNM.log
echo ----------------------------------------------- >> $RPTNM.log
netstat -tlpnu >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Socket statistics >> $RPTNM.log
echo ----------------------------------------------- >> $RPTNM.log
ss -s >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo Info from "Top" >> $RPTNM.log
echo --------------- >> $RPTNM.log
top -n1 -b | head >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo List of active processes >> $RPTNM.log
echo ------------------------ >> $RPTNM.log
ps auxf >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo List of log files that have changes in the last 30 minutes >> $RPTNM.log
echo ---------------------------------------------------------- >> $RPTNM.log
find /var/log -mmin -30 >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Tail of all log files in /var/log >> $RPTNM.log
echo --------------------------------- >> $RPTNM.log
tail /var/log/* >> $RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Recent history >> $RPTNM.log
echo -------------- >> $RPTNM.log
tail -n 100 /root/.bash_history >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Apache configuration info >> $RPTNM.log
echo ------------------------- >> $RPTNM.log
apache2 -V >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Apache module info >> $RPTNM.log
echo ------------------- >> $RPTNM.log
apache2 -l >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo List Apache virtual sites >> $RPTNM.log
echo ------------------------- >> $RPTNM.log
apache2ctl -S >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Apache full status >> $RPTNM.log
echo ------------------ >> $RPTNM.log
apache2ctl fullstatus >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Apache enabled modules >> $RPTNM.log
echo ---------------------- >> $RPTNM.log
apache2ctl -M >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo PHP configuration info >> $RPTNM.log
echo ---------------------- >> $RPTNM.log
php --ini >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo PHP extensions >> $RPTNM.log
echo -------------- >> $RPTNM.log
php -m >> $RPTNM.log 2>>$RPTNM.log
echo MYSQL Variables >> $RPTNM.log
echo -------------- >> $RPTNM.log
mysql --defaults-file==/root/scripts/backupcreds_sql.txt -e "select 'SHOW DATABASES-----------'; show databases; select 'SHOW TABLES--------'; select table_schema, table_name from information_schema.tables; select 'SHOW VARIABLES--------'; show variables; select 'SHOW USERS----------'; select User,Host from mysql.user; select 'SHOW GRANTS'; select concat('SHOW GRANTS FOR ''',user,'''@''',host,''';') from mysql.user;" >> $RPTNM.log
# echo --------------------------------------------------------------------------- >> $RPTNM.log
echo >> $RPTNM.log
echo Postfix Config, if any >> $RPTNM.log
postconf -n >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo Dmesg output of Kernel log >> $RPTNM.log
echo -------------------------- >> $RPTNM.log
dmesg >> $RPTNM.log 2>>$RPTNM.log
echo >> $RPTNM.log
echo --------------------------------------------------------------------------- >> $RPTNM.log
#echo List of open files >> $RPTNM.log
lsof -i tcp -Pn | grep LISTEN >> $RPTNM.log 2>>$RPTNM.log
lsof >> $RPTNM.log 2>>$RPTNM.log
echo IPTABLES firewall rules >> $RPTNM.log
iptables --list -nv | less >> $RPTNM.log 2>>$RPTNM.log

Leave a Reply