Script to email load average when it goes above a particular threshold

ARUN Posted in SCRIPTS
0
vi /root/load.sh
#!/bin/bash

load=`uptime | awk ‘{print $(NF-2)}’ | cut -d. -f1`
if [ $load -gt 4 ]

then

echo `uptime` | mail -s “server load is $load” [email protected]

fi

Command to delete files older that N days

ARUN Posted in LINUX COMMANDS, SCRIPTS
0

[    find /home/username/ -mtime +N -exec ls -l {} \;    ]

eg :   [    find /home/username/ -mtime +75 -exec ls -l {} \;    ]

Script to backup and restore all cpanel accounts

ARUN Posted in SCRIPTS
0

BACKUP

for i in `cat /etc/trueuserowners| grep USERNAME | cut -d: -f1` ; do /scripts/pkgacct $i /home/username/backup ; done”

RESTORE

for i in `ls -1 /backup/cpmove*` ; do /scripts/restorepkg –force $i ; done

Load average script

ARUN Posted in LOAD, SCRIPTS
0

for ((i=0; i<=2160; i++)); do uptime; sleep 120; done

Where 120 is the time in seconds

Script to take mysql backups

ARUN Posted in SCRIPTS
0

!#/bin/bash
suffix=`date +%Y%m%d`
dest=/data/backup/mysql
cmd=’/usr/bin/mysqldump’

mkdir “`date +%Y-%m-%d`”;
cd “`date +%Y-%m-%d`”;
for db in `echo ‘show databases;’ | mysql -u root –password=’[email protected]′ | grep -v ^Database$ ` ; do mysqldump –opt $db | gzip > $dest/`date +%Y-%m-%d`/$db.sql.gz ;done

# delete old dumps (retain 5 days)
#find ${dest} -mtime +5 -exec rm {} \;

 

OR

mkdir /var/lib/mysqlbackup


cd /var/lib/mysqlbackup

[  for db in `echo 'show databases;' | mysql -u root --password='BrnTW00d' | grep -v ^Database ` ; do mysqldump --opt $db | gzip > $db.sql.gz ; done    ]

Script to create multiple accounts

ARUN Posted in SCRIPTS
0

vi /root/accts.txt

while read file ; do domain=`echo $file | awk ‘{print $1}’` ; user=`echo $file | awk ‘{print $3}’` ; password=`echo $file | awk ‘{print $4}’` ; /scripts/createacct $domain $user $password ; done < /root/accts.txt