Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wanting to produce graphs of my server traffic using rrdtool, but it expects hex color codes for each line on the graph.

Since I am wanting to iterate over a varying bunch of domain data files, I would like to generate these color codes programatically. I would also like them to remain consistent for a given domain data file - so I think a hash of the domain name would be a good method to use. Problem is, I don't know where to begin.

Is there a simple algorithm that I can use in bash to hash strings (domain names) into hex color codes?

share|improve this question
up vote 5 down vote accepted

How about md5?
color=#`echo -n $domain | md5 | cut -c1-6`

The resulting variable $color will be #5ababd

share|improve this answer
Nice. Thank you. – Brent Nov 28 '09 at 17:13
note the '-n' in the edit - although the hash works equally well without it, this ensures that the MD5 sum is based only on the domain name without a trialing carriage return. – Alnitak Nov 28 '09 at 17:14
Do keep in mind that this will occasionally come up with bad colors (e.g, same as the background color). – duskwuff Nov 30 '09 at 5:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.