Nagios ( over ssh )

Configuring Nagios ( My Os is Ubuntu )

Before configuring nagios server configure the server as mail server/relay server

A. INSTALLATION

1) Download Source in /usr/local/src/

wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.2.3/nagios-4.2.3.tar.gz

wget --no-check-certificate https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz

tar -zxvf nagios-plugins-2.1.4.tar.gz

2) Add user and group

useradd nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

usermod -a -G nagios,nagcmd www-data
 (* for centos this will be usermod -a -G nagios,nagcmd apache)

3) Configurating and compiling source code nagios core:

tar -zxvf nagios-4.2.3.tar.gz

tar -zxvf nagios-plugins-2.1.4.tar.gz

cd nagios-4.2.3

install packages

apt-get install snmp

apt-get install snmpd

apt-get install mrtg

(*for centos

net-snmp-5.3.2.2-22.el5_10.1

net-snmp-libs-5.3.2.2-22.el5_10.1)

./configure --with-command-group=nagcmd --with-mail=/usr/bin/sendmail –with-httpd-conf=/etc/apache2/sites-available/

(* for centos this will be ./configure --with-command-group=nagcmd )

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

4) configuring Apache

sudo a2ensite nagios

sudo a2enmod rewrite cgi ( enable mod rewrite in httpd for centos)

service apache2 reload / restart

(* for centos it will be /etc/init.d/httpd restart /reload)

/etc/init.d/nagios start

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

5) Configurating and compiling source code nagios plugins

cd ../nagios-plugins-2.1.4/

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

sudo update-rc.d nagios defaults

(* for centos it will be

chkconfig --add nagios

chkconfig --level 35 nagios on )

B. CONFIGURATION

On Client

apt-get install libmysqlclient*-dev ( for check_mysql plugin its required )

mysql51-mysql-libs.x86_64 ( for centos)

useradd nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

cd /usr/local/src

wget --no-check-certificate https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz

tar -zxvf nagios-plugins-2.1.4.tar.gz

cd nagios-plugins-2.1.4

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

On Server

su nagios

ssh-keygen

copy the content of the file id_rsa.pub to the file /home/nagios/.ssh/authorized_keys

cd /usr/local/nagios/etc/objects

(write your own commands for remote servers which we are going to monitor via ssh agent. )

vi remote-commands.cfg ( for example see my remote-commands.cfg at the end of the document.)

cd /usr/local/nagios/etc

vi nagios.cfg and add the below line

cfg_file=/usr/local/nagios/etc/objects/remote-eommands.cfg

cd /usr/local/nagios/etc/objects

vi hostgroups.cfg ( create your hostgroups. In localhost.cfg you can find how hostgrup is written. Sample files are at the end of the document )

cd /usr/local/nagios/etc

vi nagios.cfg and add the below line

cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg

mkdir /usr/local/nagios/etc/objects/{Linux-Workstations,Windows-Workstations,Laptops,DRBL-Workstations,Local-Servers,Remote-Servers)

cd /usr/local/nagios/etc

vi nagios.cfg and add the below lines

cfg_dir=/usr/local/nagios/etc/objects/Local-Servers

cfg_dir=/usr/local/nagios/etc/objects/Linux-Workstations

cfg_dir=/usr/local/nagios/etc/objects/Windows-Workstations

cfg_dir=/usr/local/nagios/etc/objects/Laptops

cfg_dir=/usr/local/nagios/etc/objects/Remote-Servers

copy the localhost.cfg to /usr/local/nagios/etc/objects/Linux-Workstations/<system-to-monitor-ip>.cfg ( for example I have 192.168.100.199 ip so i copied file as 192.168.100.199.cfg)

vim 192.168.100.199.cfg
 remove all hostgroup entries and make the changes accordingly




For remote system monitoring write the file /usr/local/nagios/etc/objects/remote-commands.cfg like below

define command{
 command_name check_remote_disk
 # command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -e'
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_disk -w $ARG2$ -c $ARG3$ -A -I "/run/*" -I "/sys/*" -I "/dev/shm" -I "/dev" -I "/lib/*" -I "/var/lock" -I "/Thecus/*"'
 }

define command{
 command_name check_remote_load
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_load -w $ARG2$ -c $ARG3$'
 }

define command{
 command_name check_remote_swap
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_swap -w $ARG2$ -c $ARG3$'
 }

define command{
 command_name check_remote_users
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_users -w $ARG2$ -c $ARG3$'
 }

define command{
 command_name check_remote_procs
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_procs -w $ARG2$ -c $ARG3$'
 }

define command{
 command_name check_remote_ssh
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_ssh -H $HOSTADDRESS$ $ARG1$'
 }

#define command{
 # command_name check_remote_mysql
 # command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_mysql -H $HOSTADDRESS$ $ARG1$'
 #}

define command{
 command_name check_remote_pgsql
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_pgsql -H $HOSTADDRESS$ -l $ARG2$ -p $ARG3$'
 }

define command{
 command_name check_remote_http
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_http -H $HOSTADDRESS$'
 }

define command{
 command_name check_remote_ldap
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_ldap -H $HOSTADDRESS$ $ARG1'
 }

define command{
 command_name show_remote_users
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/show_users'
 }

define command{
 command_name check_remote_mysql
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_mysql -u $ARG2$ -p $ARG3$'
 }

define command{
 command_name check_remote_asterisk
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_asterisk'
 }

define command{
 command_name check_remote_ping
 command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $HOSTADDRESS$ -C '/usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5'
 }

define command{ command_name show_logged_users command_line /usr/local/nagios/libexec/check_by_ssh -p $ARG1$ -l nagios -t 30 -o StrictHostKeyChecking=no -H $ARG2$ -C '/usr/local/nagios/libexec/logged_users' }

For host write files like given (sample configuration geekonline.cfg )

define host{
 use                     remote-linux-server            ; Name of host template to use
 ; This host definition will inherit all variables that are defined
 ; in (or inherited by) the linux-server host template definition.
 host_name               GEEKHOST
 alias                   GeekHost
 address                 23.250.32.8
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             PING
 check_command            check_remote_ping!22!100.0,20%!500.0,60%
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Partitions
 check_command            check_remote_disk!22!20%!10%!/
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Current Users
 check_command            check_remote_users!22!20!50
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Total Processes
 check_command            check_remote_procs!22!250!400!RSZDT
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Current Load
 check_command            check_remote_load!22!5.0,4.0,3.0!10.0,6.0,4.0
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Swap Usage
 check_command            check_remote_swap!22!20!10
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             SSH
 check_command            check_ssh
 notifications_enabled        0
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             Logged in Users
 check_command                   show_remote_users!22!
 notifications_enabled           0
 }

define service{
 use                             local-service         ; Name of service template to use
 host_name                       GEEKHOST
 service_description             MYSQL
 check_command                   check_remote_mysql!22!root!<rootPassword>
 notifications_enabled           0
 }p

/etc/init.d/nagios/restart




http://<ip>/nagios

Compress pdf files

 

#!/bin/bash
# For this script ghostscript package is needed. either install it or download static compiled binary for it.
echo "This script will Compress all pdf files with prefix Compressed-"
echo "do you wish to run the script (y/N)"
read ans
if [[ $ans == y ]] || [[ $ans == Y ]]
then
for i in *.pdf ;do
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=Compressed-$i $i
done
else
echo Exiting..
fi

 

How to know your live/Public ip by command line

Run the below command in terminal to know your public ip address

dig -4 @resolver1.opendns.com -t a myip.opendns.com +short

Different sites through different ISP or VPN

Suppose I am running squid server with port 3218 and port 8080 is mapped with 3128 port of other squid server / VPN 

and I want the websites microsoft.com 411.com and tlo.com  and whatismyip.com shoud run through VPN then have to write a wpad.dat file like given below

function FindProxyForURL(url, host) {

if (dnsDomainIs(host, "tlo.com") ||
        shExpMatch(host, "(*.tlo.com|tlo.com)"))
        return "PROXY 192.168.100.1:8080";

if (dnsDomainIs(host, "www.411.com") ||
        shExpMatch(host, "(*.411.com|411.com)"))
        return "PROXY 192.168.100.1:8080";

if (dnsDomainIs(host, "www.microsoft.com") ||
        shExpMatch(host, "(*.microsoft.com|microsoft.com)"))
        return "PROXY 192.168.100.1:8080";



if (dnsDomainIs(host, "whatismyip.com") ||
        shExpMatch(host, "(*.whatismyip.com|whatismy.p.com)"))
        return "PROXY 192.168.100.1:8080";


else
return "PROXY 192.168.100.1:3128; DIRECT";      <-- This line can be replaced  by return "DIRECT";    if  the ip is bypassed

 }

 

 and in browser  for example in firefox  in network settings Automatic proxy Configuration url i hav to add the line http://IP web server where wpad file is kept >/wpad.dat

Disk Check with Alert

This script checks the disk usage of servers and emails. sshpass is used only for pfsense for the rest servers ssh keys are used to connect.

#!/bin/bash
 DATE=`date +%Y-%m-%d`
 logfolder=/var/log/disk_usage/
 logfile=$logfolder/$DATE-disk-usage.log
 alertlogfile=$logfolder/$DATE-disk-usage-alert.log
 key=/example/keys/id_rsa_nagios
 sendemail=/example/scripts/sendEmail.pl
 SENDEMAIL=/example/scripts/sendEmail.pl
 MAIL_FROM="My Domain <automation@example.com>"
 MAIL_TO="admin@example.com"
 MAIL_HOST='example.com:587'
 MAILUSER=emailuser@example.com
 MAILPASS='emailuserpass'
 subject=$DATE-disk-usage-alert
 if [ ! -d $logfolder ]
 then
 mkdir -p $logfolder
 fi
 #addspace=`echo "" >> $logfile`
 ALERT=80
 IP=(192.168.0.10 192.168.0.20 192.168.0.30 192.168.0.40 192.168.0.50 192.168.0.60 192.168.0.10 192.168.0.70 192.168.0.10 192.168.0.80) # my server ips

function alert
 {
 grep -vE '^Filesystem|tmpfs|cdrom|devfs' | awk '{ print $5 " " $1 " " $6 }' | while read output;
 do
 #    echo output is $output for $Host
 usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f 1 )
 partition=$(echo $output | awk '{ print $2 }' )
 usem=$(echo $output | awk '{print $3}')
 # echo usep=$usep  usem=$usem partiton=$partition
 if [ $usep -ge $ALERT ]; then
 #echo "Running out of space \"$partition ($usep%)\" on $Host as on $DATE" |
 #mail -s "Alert: Almost out of disk space $usep" $ADMIN
 echo "Running out of space  \"$partition ($usep%) $usem\""  >> $alertlogfile
 fi
 done

}

## only for pfsense
 #:'
 echo "" >> $logfile
 Host=`sshpass -p PASSWD ssh -o StrictHostKeyChecking=no  -o 'KbdInteractiveDevices no'  root@192.168.0.1 hostname`
 echo "Hostname is $Host"
 echo "            $Host" >> $logfile
 echo "" >> $logfile
 sshpass -p PASSWD ssh -o StrictHostKeyChecking=no -o 'KbdInteractiveDevices no'  root@192.168.0.1 df -P -h >> $logfile
 sshpass -p PASSWD ssh -o StrictHostKeyChecking=no -o 'KbdInteractiveDevices no' root@192.168.0.1 df -P -h | alert
 echo "-----------------------------------------------------------------------" >> $logfile
 #'

#exit

function disk-check_local
 {
 ip=$1
 echo $ip
 echo "" >> $logfile
 Host=`ssh -o StrictHostKeyChecking=no -i "$key" restricted@$ip hostname`
 echo "Hostname is $Host"
 echo "            $Host" >> $logfile
 echo "            $Host" >> $alertlogfile
 echo "" >> $logfile
 echo "" >> $alertlogfile
 ssh -o StrictHostKeyChecking=no -i "$key" restricted@$ip df -P -h >> $logfile
 ssh -o StrictHostKeyChecking=no -i "$key" restricted@$ip df -P -h | alert
 echo "-----------------------------------------------------------------------" >> $logfile
 echo "-----------------------------------------------------------------------" >> $alertlogfile
 }

for i in ${IP[@]}; do
 echo "processing $ip"
 disk-check_local $i
 #  echo "done with $ip"
 done

#exit
 cat $logfile
 cat $alertlogfile
 report=`cat $alertlogfile`

$SENDEMAIL -f "$MAIL_FROM" -t $MAIL_TO -s $MAIL_HOST -xu $MAILUSER -xp $MAILPASS -u "$subject" -m "$report" -a $logfile

Monitor Server Status and Notify when up/down

#!/bin/bash
## Global variables
TO=admin@example.com
CC=admin@example.com
FROM="Your Server Remote Monitor <automation@example.com>"
user=gmailuser
pass=gmailuserpass
SMTP=smtp.gmail.com:587
nitstatus=/tmp/nit

###### Check line up or down 
ping -c3 example.com ; [ $? == 0 ] && checkstatus=up || status is checkstatus=down ; clear ; echo status is  $checkstatus |tail -1

if [[  ! -f $nitstatus ]];
then
echo up > $nitstatus
fi
oldstatus=`cat /tmp/nit`
echo old status is $oldstatus
echo $checkstatus
if [[ $checkstatus == "up" ]]
then
newstatus=up
elif [[ $checkstatus == "down" ]]
then
newstatus=down
fi
###### Email notification ###

echo new status is $newstatus

if
[[ $oldstatus != $newstatus ]]
then

echo "Your Server server is $newstatus"
echo $newstatus > $nitstatus
                  if [[ $newstatus == "down" ]]
                  then
                  echo sending email for down
                  /neuralit/scripts/sendEmail.pl -f "$FROM" -t "$TO"  -s  "$SMTP" -xu "$user" -xp "$pass"  -u "Your Server Server is Down" -m "
Your Server server is down on `date +%T`"
                  elif [[ $newstatus == "up" ]]
                  then 
                  echo sending email for up
                  /neuralit/scripts/sendEmail.pl -f "$FROM" -t "$TO"  -s  "$SMTP" -xu "$user" -xp "$pass"  -u "Your Server Server is Up" -m "
Your Server server is up on `date +%T`" 
                  fi

else
echo no change
fi

Get inventory in the lan

This script needs whoe network pcs having linux os, I have used sshpass for understanding you can use ssh keys also. This is written for 3  seperate networks in lan ( 192.168.10.0/24 192.168.100.0/24 and 192.168.20.0/24)

The script will provide the username ip address mac address memory cpu info (* note my user having . in username so i wrote accordingly. you may have different and so you have to edit the script according to you.




#!/bin/bash
 downhosts=/var/log/hostsdetails/down
 uphosts=/var/log/hostsdetails/up
 inventory=/var/log/hostsdetails/inventory
 old=/var/log/hostsdetails/old/
 pass=PASSWORD
 net=(10 100 20)
 hour=0
 start_time=$(date +%s)

mv "$downhosts" "$old"
 mv "$uphosts" "$old"
 mv "$inventory" "$old"
 echo "USERNAME <-> IP-ADDRESS <-> MAC-ADDRESS <-> MEMORY <->  CPU-INFORMATION" >> $inventory

for i in ${net[@]}; do
 echo  "for '$i'th network"
 for j in $(seq 1 254); do ip=192.168.$i.$j && ping -c 1 $ip>/dev/null; [ $? -eq 0 ] && echo "$ip is UP" && mac=`sshpass -p "$pass" ssh -o StrictHostKeyChecking=no root@"$ip" ifconfig | grep eth0 | awk '{ print $5}'` && mem=`sshpass -p "$pass" ssh -o StrictHostKeyChecking=no root@"$ip"  free -m | grep Mem | awk '{print $2}'`&& user=`sshpass -p "$pass" ssh -o StrictHostKeyChecking=no root@"$ip" ls -l /proc /| awk '{print $3}'| grep "\." | uniq` && if [ "$user" == "" ]; then  echo Unable to get the logged in user information for $ip; fi && cpu=`sshpass -p "$pass" ssh -o StrictHostKeyChecking=no root@"$ip" cat /proc/cpuinfo |grep 'model name' | head -n 1 | cut -d ":" -f 2` && echo "$user <-> $ip <-> $mac <-> $mem <-> $cpu" >> $inventory && echo "$ip" >> $uphosts || echo "$ip" >> $downhosts ; done
 done

finish_time=`date +%s`
 time_taken=`expr $finish_time - $start_time`
 if [ $time_taken -ge 60 ];
 then
 min=`expr $time_taken / 60`
 sec=`expr $time_taken % 60`
 if [ $min -ge 60 ];
 then
 hour=`expr $min / 60`
 min=`expr $min % 60`
 fi
 fi
 hour=`printf "%0*d\n" 2 $hour`
 min=`printf "%0*d\n" 2 $min`
 sec=`printf "%0*d\n" 2 $sec`
 echo "Script execution time: $hour:$min:$sec"

 

Mysql Backup script using mysqldump

This script is written to backup and email the status of backup

Please make sure to replace your domain with example.com, and user and passwords accordingly




#!/bin/bash

### GLOBAL VARIABLES ###
 HOST=`hostname`
 MYSQL="/usr/bin/mysql"
 MYSQLDUMP="/usr/bin/mysqldump"
 MYSQL_USER=backupuser
 MYSQL_PASS=DBPASSWORD
 TSTAMP=`date +%F`
 BACKUP_DIR=/example/backup/db/$HOST
 mkdir $BACKUP_DIR/$TSTAMP
 databases=`$MYSQL -u $MYSQL_USER -p$MYSQL_PASS -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|phpmyadmin)"`
 DB_VERSIONS=7
 DELVERSION=`expr "$DB_VERSIONS" + 1`
 DELDATE=`date +%F --date="$DELVERSION days ago"`

### EMAIL VARIABLES ###

TO=admin@example.com
 FROM="Backup Automation <automation@example.com>"
 EMAILUSER=user@mydomain
 EMAILPASS=PASSWORD
 SMTP=mail.example.com
 SUBJECT="`hostname` - Backup status (DB) : $TSTAMP"
 SENDEMAIL="/example/scripts/sendEmail.pl"

###################### Creating Fresh Backup ###################

STARTTIME=`date +%s`
 START=`date +%r`

for db in $databases; do
 $MYSQLDUMP --routines --triggers --force --opt --max_allowed_packet=2G -u $MYSQL_USER  -p$MYSQL_PASS $db  > "$BACKUP_DIR/$TSTAMP/$db.sql" && mv "$BACKUP_DIR/$TSTAMP/$db.sql" "$BACKUP_DIR/$TSTAMP/$TSTAMP-$db.sql"
 done

BTIME=`date +%s`
 BT=`date +%r`
 BSTATUS=`echo $?`
 if [[ "$BSTATUS" == 0 ]]
 then
 BACKUPSTATUS=SUCCESSFULL
 else
 BACKUPSTATUS=FAILED
 fi

#for db in $databases;do
 #     $MYSQLDUMP --force --opt --routines --user=$MYSQL_USER -p$MYSQL_PASS --databases $db | gzip > "$BACKUP_DIR/$TSTAMP/$db.sql.gz" && mv "$BACKUP_DIR/$TSTAMP/$db.sql.gz" "$BACKUP_DIR/$TSTAMP/$TSTAMP-$db.sql.gz"
 #done

####################### Zipping Backups #########################

for db in $databases; do gzip -f $BACKUP_DIR/$TSTAMP/$TSTAMP-$db.sql; done
 ZSTATUS=`echo $?`
 CTIME=`date +%s`
 CT=`date +%r`

if [[ "$ZSTATUS" == 0 ]]
 then
 ZIPSTATUS=SUCCESSFULL
 else
 ZIPSTATUS=FAILED
 fi

####################### Deleting old backups ########################

echo rm -frv "$BACKUP_DIR/$DELDATE" >> /tmp/deleteinfo
 rm -frv "$BACKUP_DIR/$DELDATE"
 DSTATUS=`echo $?`

if [[ "$DSTATUS" == 0 ]]
 then
 DELSTATUS=SUCCESSFULL
 else
 DELSTATUS=FAILED
 fi
 #find "$BACKUP_DIR" -mtime +"$DELDATE" |while read DEL ; do rm -frv "$DEL";done

ENDTIME=`date +%s`
 END=`date +%r`

$SENDEMAIL -f "$FROM" -t "$TO" -s "$SMTP" -xu "$EMAILUSER" -xp "$EMAILPASS" -u "$SUBJECT" -m "
 Databases : `echo $databases| tr ' ' ,`

Summary :

DB Backup started at $START
 DB Backup finished at $BT
 DB Backup time is `expr $BTIME - $STARTTIME` seconds

DB Zipping starged at $BT
 DB Zipping finished at $CT
 DB Zipping time is `expr $CTIME - $BTIME` seconds

DB Deletion started at  $CT
 DB Deletion finished at $END
 Old DB Deleting time is `expr $ENDTIME - $CTIME` seconds

Total Time is `expr $ENDTIME - $STARTTIME` seconds

BACKUP is $BACKUPSTATUS
 GZIPPING SQL DB FILES is $ZIPSTATUS
 DELETING OLDVERSION is $DELSTATUS
 "
 echo Done

YUM repository configuration in RHEL 7

Adding local repository ( Using DVD )

1) mkdir /media/cdrom

2 ) mount /dev/cdrom /media/cdrom

3 ) create a repofile by following command

vi /etc/yum.repos.d/rhel.repo

name=Local Repository
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Adding external repositories

1 ) cd /tmp

2) wget https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
3) install the downloaded rpms

4)  sudo sed -i ‘s/enabled=0/enabled=1/g’ /etc/yum.repos.d/remi.repo

5) (optional )vi /etc/yum.repos.d/remi.repo

disable all test repositories  by setting value enabled=0

type command yum repolist to view list of repositories

Configuring apache mariadb and phpmyadmin on RHEL 7

1 ) Install apache mariadb php and phpmyadmin on server by using following command

yum install php phpmyadmin httpd mariadb

2)  type below command and set the password for root

mysql_secure_installation

3) vim  /etc/httpd/conf.d/phpMyAdmin.conf

in the section/container <Directory /usr/share/phpMyAdmin/> </Directory>

add the following two lines.

Options Indexes FollowSymLinks
Require all granted

4) add firewall rules  and reload firewall

firewall-cmd –permanent –add-port=80/tcp
firewall-cmd –permanent –add-port=80/udp
firewall-cmd –permanent –add-port=443/tcp
firewall-cmd –permanent –add-port=443/udp

firewall-cmd –reload

OR

firewall-cmd –permanent –add-service=http

systemctl restart firewalld

5) Now restart apache service by typing

service httpd restart or

systemctl restart httpd.service

6) checking and adding apache and mariadb services to startup

systemctl is-enabled httpd

systemctl is-enabled mariadb

if it says its disabled then enable it by following command.

systemctl enable httpd

systemctl enable mariadb