Finding unique record in a Linux file

I needed to find the unique hosts that had connected to a machine through a plug gateway. The host name was in column 10




cat ¬†messages.0 | grep ” connect” |awk ‘{print $10}’ | sort -u

Advertisements
Finding unique record in a Linux file

Checking xtrabackup has worked

As part of running backups I like a notification if one has failed. As far as I can find so far there are no return codes from the innobackex script that I could use so at the moment I am just checking the output for the line innobackupex-1.5.1: completed OK

/usr/bin/innobackupex-1.5.1 $BACKUP_DIR 2> /home/backup/logs/backup-$BACKUP_FILE.log
less /home/backup/logs/backup-$BACKUP_FILE.log | grep “innobackupex-1.5.1: completed OK”
if [ $? -ne 0 ] # string not found, ie. backup failed
then
echo “Backup failed”
mail -s “MySQL Production Backup failed” ????@????????.com
exit 1
else
echo “Backup Ok”
fi

Checking xtrabackup has worked

Changing Settings for all tables

As part of my migration to MariaDB I wanted to change all the wordpress tables from MyISAM to INNODB. Of course you can do this one table at a time with

alter table fred engine=innodb;

Personally I prefer to automate where ever possible so  I created the following linux shell script to convert all the tables in one database in one go

DBNAME=”blog”
DBUSER=”xxxx”
DBPWD=”xxxxxxxx”
for t in $(mysql -u$DBUSER -p$DBPWD –batch –column-names=false -e “show tables” $DBNAME);
do
echo “Converting table $t”
mysql -u$DBUSER -p$DBPWD -e “alter table $t engine=innodb” $DBNAME;
done

This script could of course be used for many things by just changing the SQL in line 7

Changing Settings for all tables