select 'use '+d.name+char(10)+'go'+char(10)+'BACKUP LOG '+d.name+' WITH TRUNCATE_ONLY'+char(10)+'go'+char(10)+'dbcc shrinkfile ('''+mf.name+''',100)'+char(10)+'go' 
from sys.databases d
inner join sys.master_files mf on mf.database_id=d.database_id
where mf.type=1
and d.state=0