Shave and a haircut - two bits

What is the origin of the musical phrase (or rhythmic pattern) known as “shave-and-a-haircut-two-bits”?
It is often used as a musical cliche at the end of a performance, as an obnoxious way to knock on a door, etc.
I assume it is quite old, dating from the time when barbers charged “two bits” for a shave and a haircut, but what is the Inside Story? Does it perhaps originate with barbershop quartet songs?

Welcome to the Board!

Here are a couple of links, but nothing too conclusive:

http://boards.straightdope.com/sdmb/showthread.php?threadid=26968

http://boards.straightdope.com/sdmb/showthread.php?threadid=38661

One mentions Cecil having covered this, but I didn’t find it in the archives.

This what I turned up.
http://jrnl.net/news/00/Nov/jrn26171100.html