Posts Tagged ‘Bash’

Bash script to execute a MariaDB query multiple times

This simple bash script will execute a query 100 times against a MySQL instance. It also uses the time command to report how long the entire process took. I use this for some very simple bench-marking. The query used here creates a temporary table and inserts 100K rows into it. You need the sequence engine […]

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 […]

Monitor /tmp usage on Linux

Just a quick post to show how to monitor usage of /tmp on a Linux system. Setup a cron job as follows… ?View Code BASH* * * * * df -h | grep "/tmp" >> /tmp/tmp.log This job will run every one minute logging details of /tmp usage to a file called tmp.log. To report […]

Backing up the structure of MySQL databases

Today I wanted a quick and easy way to generate a backup of the structure of all MySQL databases in one easy hit. Here’s a couple of ways you can do this with the tools you’re likely to find everywhere. Firstly, we can use the following query to generate a list of mysqldump commands. The […]

Parse MySQL Slow Logs with mysqlsla

Here’s a bash script that you can use to parse multiple MySQL Slow Query Log files, in one sweep, into something much more understandable. The script uses the handy utility mysqlsla so make sure this is in your path.  mysqlsla parses, filters, analyzes and sorts MySQL slow, general, binary and microslow patched logs in order […]