Can set iTerm2 tab colors from the command line? I'd like to automatically set a terminal tab's color when certain things happen, like when I run teamocil, ssh or other programs.  

I know how to watch the .bash_history file.  But I don't know how to programmatically change the tab color.  Is there a way?

(not related: 1, 2)
It appears a script like this could work for you. This is using zsh, but should work or only require a little bit of editing to work with bash. 

Essentially what it does is aliases ssh to this color ssh command which changes the color of the tab and then runs ssh.