Archive for the ‘Bash’ Category

Progress bars in BASH with pv

Way back in 2009 I wrote a post about how to display progress bars in Powershell. The same thing is possible in bash with pv. If it’s not available in your shell just do… ?View Code BASHyum install pv Or equivalent for your platform. The following example compresses a file into a tar archive reporting […]

Launch a MongoDB Cluster for testing

Here’s a bash script I use to create a sharded MongoDB Cluster for testing purposes. The key functions are mongo_setup_cluster and mongo_teardown_cluster. The script will created a Mongo Cluster with 2 shards, with 3 nodes each, 3 config server and 3 mongos servers. UPDATE 2015/10/02 I’ve found out about an undocumented option available to set […]

Highlight text using Grep without filtering text out

Here’s a neat little trick I learned today I thought was worth sharing. Sometimes I want to highlight text in a terminal screen using grep but without filtering other lines out. Here’s how you do it… ?View Code BASHmysqlbinlog mysql-bin.000473 | grep –color -E ‘^|not closed’; The important part is the regexp in grep. The […]

6 Useful Bash tips I wish I knew from day zero

Here’s a few bash commands tricks I wished I’d been shown when I first picked up the shell. Please share any additional favorites you have. Repeat the last command with sudo How often do you type… ?View Code BASHyum install long-list packages-devel Only to be told… You need to be root to perform this command. […]

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