Mint_xbmcCleanup is a project mainly written in Shell, it's free.
xbmcCleanup bash script by BaerMan altered to work with mysql database backend
XBMC Orphans and Widows by BaerMan altered to work with mySQL storage instead of sqlite. Useful for centralised xbmc setups!
See Settings here: http://wiki.xbmc.org/index.php?title=Advancedsettings.xml#.3Cmusicdatabase.3E.2F.3Cvideodatabase.3E