Archive for the ‘Bash’ Category

Copy date stamped backups with a regex & scp

Lets assume you have a directory of date stamped backups you want to scp to another location… backup_20141003.tar.gz backup_20141004.tar.gz backup_20141005.tar.gz backup_20141006.tar.gz backup_20141007.tar.gz backup_20141008.tar.gz backup_20141009.tar.gz scp can accept a regex like below to do this as a one-liner. Note the quotes are required for the expression to work. ?View Code BASHscp "user@hostname:/data/backup/backup_2014100[3-9].tar.gz" /path/to/location/ You should see […]

Replace the Engine used in mysqldump

Just a little bash snippet to replace the ENGINE type used in a mysqldump. Slightly modified from this stackoverflow thread to perform the dump and replacement in a single step. To dump to a file… ?View Code BASHmysqldump -h hostname -u root -p –routines –databases db_name | sed -re ‘s/^(\) ENGINE=)MyISAM/\1TokuDB/gi’ > output.sql To copy […]

Linux Tip: Output error messages to syslog from cron

I wanted to find a way of running a script in cron and output the exit code, and error message, to syslog if it failed. Here’s what I came up with… ?View Code BASHoutput=`/usr/bin/scripts/test.sh 2>&1`; code=$?; if [ "$code" -ne 0 ]; then err_msg=`echo "$output" | tail -1`; logger -t "CRONERROR" "Exit Code = $code: […]

Linux Tip: Add datetime stamp to bash history

I like to know what’s happening on my Linux servers. The output of the history command doesn’t include a datetime stamp by default.¬† To rectify this open the global profile…. ?View Code BASHvi /etc/profile Add the following line to the bottom. ?View Code BASHexport HISTTIMEFORMAT="%h %d %H:%M:%S " The output of the history command will […]

pmp-check-mysql-deleted-files plugin issue

I’ve been busy setting up the Percona Nagios MySQL Plugins¬† but ran into an issue with the pmp-check-mysql-deleted-files plugin; UNK could not list MySQL’s open files After a little debugging we tracked this down to a problem caused by running multiple instances of mysqld. This is something the script author (Baron Schwartz) mentions in his […]