Define a property with your server instance and databases names.
<property name="SQLInstance" value="MySQLServer">
<property name="databases" value="Test_0001,Test_0003,Test_0003" />
<foreach item="String" in="${databases}" delim="," property="Database">
<echo message="Running my scripts on the databases..." />
<exec program="sqlcmd" commandline="-b -s ${SQLInstance}" -o ${Database}.log -d ${Database}
</foreach>
That would be the best approach to take.