[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:
Post a Comment