Saturday, January 26, 2019

CentOS6 and 7 information collection script.

In case you are making major changes to the Linux systems and got multiple OS - Below script may help to enter your choice of OS to select and backup the important directories files and commands output. This is a standard layout. Where unless the right arguments are provided on the command line to the script - The The script does not give up and on providing wrong arguments script still waits for the correct argument. The script can be modified by adding your choice of application directories in the path and tar them same with the commands and other important files.

[root@desk-03 tmp]# cat osinfocollect.sh
# Author: Raj Sangvikar
# DATE:01-25-2018
# Script for saving networking configuration and system information.
# copy fstab, hosts, mount, ifcfg-* files, nsswitch.conf, sssd.conf, ldap.conf, OS version.


TODAY=`date +%Y-%m-%d.%H:%M:%S`
NEWDIR=`date +%Y-%m-%d`
DESTINATION="/var/tmp/sysbak_$NEWDIR"
#OSVERSION=$(cat /etc/redhat-release | awk '{print $7}' |  cut -f1 -d.)

# Create a new Directory in the /var/tmp

mkdir -p $DESTINATION

# Copy the important /etc directory and tar in .gz format in  above directory

tar -czvf $DESTINATION/etc.tar.gz /etc/ > /dev/null 2>&1

# We will need some inportant commands output saved in the above directory in the file named "commands_data_output.txt"

uptime >  $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

mount  >>  $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

uname -a >>  $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

df -h >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

free -m >> $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

ifconfig -a >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

lvdisplay >> $DESTINATION/commands_data_output.$TODAY

echo "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

route -n >> $DESTINATION/commands_data_output.$TODAY

echo  "=============================================================================" >> $DESTINATION/commands_data_output.$TODAY

echo "Enter 1 for CentOS-6 And 2 for CentOS-7:"

while read num
do

if [[ $num -eq 1 ]];
then
iptables -L -t nat >> $DESTINATION/commands_data_output.$TODAY
echo "Necessary commands output files and directories are backed up in $DESTINATION"
exit 0
else
if [[ $num -eq 2 ]];
then
firewall-cmd --list-all >> $DESTINATION/commands_data_output.$TODAY
echo "Necessary commands output files and directories are backed up in $DESTINATION"
exit 0
else
echo "Please enter 1 for CentOS-6 And 2 for CentOS-7:"
 fi
fi
done

========================================================================

[root@desk-03 tmp]# ./osinfocollect.sh

Enter 1 for CentOS-6 And 2 for CentOS-7:
5
Please enter 1 for CentOS-6 And 2 for CentOS-7:
3
Please enter 1 for CentOS-6 And 2 for CentOS-7:
1
Necessary commands output files and directories are backed up in /var/tmp/sysbak_2019-01-26


Happy Scripting!


Disclaimer: This is for my reference only - Use at your own discretion.

No comments: