I am trying to create a for loop with two list files that will basically echo the script to change the dbowner of multiple databases. The list files contain multiple servers and the login name list contain multiple login names. But they are line separated in order to match each database with the login name.
This is what I have so far but it is obviously taking the first server name and looping it through each login name and then moves onto the next server name.
for servername in $(cat servername.list); do
for loginname in $(cat loginname.list); do
echo "USE $servername"
echo "go"
echo "EXEC sp_changedbowner '$loginname'"
echo "go"
echo "USE master"
echo "go"
echo ""
done
done
I want the output to be this:
USE server1
go
EXEC sp_changedbowner 'login1'
go
USE master
go
USE server2
go
EXEC sp_changedbowner 'login2'
go
USE master
go