Start, Stop & Restart NFSv4 Services Script in CentOS


#!/bin/bash

_me=${0##*/}

RHEL/CentOS init.d Script Names
_server=”/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock /etc/init.d/nfs”
_client=”/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock”
_action=”$1″

Running Client Script stop|start|restart|status
runme(){
local i=”$1″
local a=”$2″
for t in $i
do
$t $a
done
}

usage(){
echo “$_me start|stop|restart|reload|status”;
exit 0
}

[ $# -eq 0 ] && usage

Main Logic
case $_me in
nfs.server) runme “$_server” “$_action” ;;
nfs.client) runme “$_client” “$_action” ;;
*) usage
esac

Advertisements

Scanning Virus in Linux Using ClamAV


#!/bin/bash

Install EPEL Repository
64 Bit
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

32 Bit
rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Install Required ClamAV Packages
yum -y install clamav clamd

Clamd Services
/etc/init.d/clamd on
chkconfig clamd on
/etc/init.d/clamd start

Update ClamAV’s from Source
/usr/bin/freshclam

Scanning Virus on CentOS System by Giving Below Commands
clamscan -r /home
clamscan -r /var

Cronjob Details
00 22 * * * Path-Script/clamav-scan.sh (Every Day Night 11PM)

Path Details
clamscan -r /home
clamscan -r /var
clamscan -r /root

Output Details
clamscan -r /var/www
/var/www/html/index.html: OK

Scan Summary
Known viruses: 3965211
Engine version: 0.98.7
Scanned directories: 2
Scanned files: 1
Infected files: 0
Data scanned: 0.01 MB
Data read: 0.01 MB (ratio 1.00:1)
Time: 15.603 sec (0 m 15 s)

How to save History in linux


How to save History in Linux :
————————————–
We can save history by using command script in command prompt.

Output Details :
——————-
chaitanya-GA-78LMT-S2 ~ # ls
history.log
Check with vim history.log  –> You can see what you have done from total day history will be save.

history

Start the Script :
——————–
chaitanya-GA-78LMT-S2 ~ # script history.log
Script started, file is history.log

Exit the Script :
——————-
Press Ctrl+d
chaitanya-GA-78LMT-S2 ~ # exit
Script done, file is history.log

RSYNC script for automated backup for CentOS


#!/bin/bash

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=~/.ssh/id_rsa
RUSER=root
RHOST=0.0.0.0
RPATH1=/var/www/html
RPATH2=/home/sshuser/sqldump
LPATH1=/var/www
LPATH2=/home/sshuser
DT=$(date +%d%m%y)

rm -f /home/sshuser/sqldump/*sql
$SSH -i $KEY $RUSER@$RHOST mysqldump -u root -ppassword databasename > /home/sshuser/sqldump/databasename.sql
$RSYNC -tav -e “$SSH -i $KEY” $RUSER@$RHOST:$RPATH1 $LPATH1
cd /home/sshuser/sqldump/

mysql -u root -ppassword databasename < databasename.sql

Re-Starting MySQL & Web Service
service mysqld restart
service httpd restart

Path Details
/home/sshuser/sqldump

Output Details in Localhost
/home/sshuser/sqldump
databasename.sql
/var/www/html
Remote Server Html Files will be Copied to Localhost /var/www/html
databasename.sql Backup will Done from Remote Server to localhost Server Backup Path /home/sshuser/sqldump
databasename.sql will Restore in localhost Database

Phpmyadmin for CentOS


PHPMyadmin :
——————
phpMyAdmin is an open source tool used for the administration of MySQL. In addition to offering the capability to perform administration tasks such as creating, editing, or deleting databases, and managing users and permissions, phpMyAdmin provides a graphical user interface to do all of these tasks

Features of phpMyAdmin :
———————————
1) Friendly web interface
2) Supported most of the MySQL features
3) Browse and drop databases, tables, views, fields and indexes.
4) Create, copy, drop, rename and alter databases, tables, fields and indexes
5) Manage MySQL users and there privileges
6) Import data from CSV and SQL
7) Administering multiple servers

Output Details :
——————-
Output –> http://IP-Address/phpmyadmin

Manual Installation :
————————-
yum -y update

yum -y install phpmyadmin

service httpd restart

Phpmyadmin Script for CentOS :
—————————————–
#!/bin/bash

echo “Add the EPEL Repository”

rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

echo “Updating Packages”

yum -y update

echo “Install phpMyAdmin”

yum -y install phpmyadmin

echo “Re-Starting Apache Service”

service httpd restart

echo “Installation is Completed”

echo -e “Please check with http://Ip-address/phpmyadmin&#8221;

echo -e “Login Details: Use MySQL Username & Password”

CentOS Server Backup Script for DB, Users & Services


CentOS Server Backup Script for DB & Services :
———————————————————————
#!/bin/bash

echo -e “Centos-Server-Backup-Script”

echo -e “Backuping System files, DataBase files, User files & Services”

echo -e “Check List”

function checkLists {
if ! [ -f $backuplistfile ] ; then
echo “Missing backup Listfile. create $backuplistfile”
exit
fi;
}

echo -e “Check Backup Status”

function checkBackupStatus {
if $BACKUP_DAILY_ONLY_ONCE ; then
if [ -f $backupdir/0/$filename ] ; then
echo “Backup already exist – try again tomorrow.”
exit;
fi;
fi;
if [ -d $tempdir ] ; then
echo “”
echo “Backup is already running. remove temp folder to reset.”
exit;
fi;
}

echo -e “Create Temporary Folder”

function createTemporaryFolder {
printf “Creating temporary directory.. ”
if $WRITE_CHANGES ; then
mkdir $tempdir
printf “Ok\n”
else printf “Skipping\n”
fi;
}

echo -e “Delete Old Backup”

function deleteOldestBackup {
if $WRITE_CHANGES ; then
if [ -d $backupdir/$1/ ] ;
then
echo “Deleteing Number $1”;
rm -r -f $backupdir/$1/ ;
fi;
fi;
}

echo -e “Shift Backup”

function shiftBackup {
if [ -d $backupdir/$1/ ] ; then
printf “Moving Number $1 to Number $2.. “;
if $WRITE_CHANGES ; then
mv $backupdir/$1 $backupdir/$2/ ;
printf “Ok\n”
else printf “Skipping\n”
fi;
fi;
}

echo -e “Shift Backups”

function shiftBackups {
for (( c=$BACKUP_COPIES; c>0; c– ))
do
b=$c
let “b -= 1”
shiftBackup $b $c
done
}

echo -e “Dump Sql”

function dumpSQL {
printf “Regenerating DB list file.. “;
if $WRITE_CHANGES ; then
mysql -u $SQL_USER -p$SQL_PASSWD -Bse ‘show databases’ > $listfile
printf “Dumping SQL Databases.. “;
cat $listfile | while read line
do
dbname=$line
if [ $line != “information_schema” ] ;
then
mysqldump –events –ignore-table=mysql.events -u $SQL_USER -p$SQL_PASSWD $dbname > $tempdir/$dbname.sql
fi
done
printf “Ok\n”
else printf “Skipping\n”
fi;
}

echo -e “Create Backup”

function createBackup {
echo “Creating TGZ Backup file for..”;
echo “directories:”
cat $backuplistfile | while read line
do
for d in $line; do
echo $d

echo  -e “take target directory to backup and replace / with _ for backup filename”

target_backup_file=$tempdir/${d//[\/]/_}$filename
if $WRITE_CHANGES ; then
tar zcfP $target_backup_file $d > $workdir/log/$filename
fi;
done
break
done
echo “databases”
if $WRITE_CHANGES ; then
tar zcfP $tempdir/db.$filename $tempdir/*.sql > $workdir/log/db.$filename
fi;
}

echo -e “Move Backup”

function moveBackup {
printf “Move from temp to Backup Number 0.. “;
if $WRITE_CHANGES ; then
mkdir $backupdir/0/
mv $tempdir/*$filename $backupdir/0/ ;
printf “Ok\n”
else printf “Skipping\n”
fi;
}

echo -e “Clean Backup”

function cleanBackup {
printf “Cleaning.. “;
if $WRITE_CHANGES ; then
rm -r -f $tempdir/
printf “Ok\n”
else printf “Skipping\n”
fi;
}

echo -e “Start Backup”

function startBackup {
if $DISABLED ; then
echo “Skipping backup – script disabled”
exit
else
checkLists
checkBackupStatus
if $WRITE_CHANGES ; then
echo “Starting Backup”
else
echo “Running in test mode”
fi;

echo -e “delete oldest backup”
deleteOldestBackup $BACKUP_COPIES

echo -e “shift the middle snapshots(s) back by one, if they exist”
shiftBackups

echo -e “dump sql dbs”
dumpSQL

echo -e “create new backup”
createBackup

echo -e “move to location 0”
moveBackup

echo -e “clear temp for the next run”
cleanBackup
fi;
}

echo -e “Load Settings”

SCRIPTDIRECTORY=$(cd dirname $0 && pwd)
cd $SCRIPTDIRECTORY
if [ -f settings.cfg ] ; then
echo “Loading settings…”
source settings.cfg
else
echo “ERROR: Create settings.cfg (from settings.cfg.example)”
exit
fi;

echo “Starting Backup”

startBackup

echo -e “Backup is Finished”

echo
if $showfsz ; then
df -h
fi;

echo “All done”