This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to generate MD5 hashes with a Bash script

26 Jan 2009

The following simple Bash script can be used to generate random MD5 hashes. To change the amount of hashes generated, you only need to change the value of the "limit" variable:

#!/bin/bash

counter=0
limit=10

while [ "$counter" -lt "$limit" ]
do

md5 -s "$counter $RANDOM `date`" | grep -o "[a-z0-9]\{32\}"
let "counter += 1"

done

echo

exit 0

To run this script from the command line (in my examples below the script is saved to "md5.sh"), you would use the command line to navigate to its directory and enter:

sh md5.sh

To run this script from the command line and save the output to a file, you would use the command line to navigate to its directory and enter:

sh md5.sh > output.txt

If you’re working on a Mac, you can run this script by double-clicking it in the Finder if you give the file a ".command" extension instead of ".sh", just remember to modify its permissions to executeable first.

Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.