I'm reading a .txt file using a while loop:
baseFileDir=./Base_Database_Files/
if [ -f "./SqlFiles.txt" ]; then
while IFS= read -r line || [[ -n "$line" ]]
do
sqlFilePath=${baseFileDir}$line
echo "Executing: $sqlFilePath"
sqlcmd -S $server,$port -U $user -P $password -d $database -I -i "$sqlFilePath" < /dev/null
done <./SqlFiles.txt
fi
sqlcmd
have problem with $lin
. Here is the output:
Executing: ./Base_Database_Files/MyScript.sql
': Invalid filename.base_Files/MyScript.sql
but if I hardcode the line ./Base_Database_Files/MyScript.sql
i.e.
baseFileDir=./Base_Database_Files/
if [ -f "./SqlFiles.txt" ]; then
while IFS= read -r line || [[ -n "$line" ]]
do
sqlFilePath=./Base_Database_Files/MyScript.sql
echo "Executing: $sqlFilePath"
sqlcmd -S $server,$port -U $user -P $password -d $database -I -i "$sqlFilePath" < /dev/null
done <./SqlFiles.txt
fi
it seems to be executing the script properly. i.e.
Executing: ./Base_Database_Files/MyScript.sql
Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'UIX_ALARM_NOTIFICATION_1' has maximum length of 2004 bytes. For some combination of large values, the insert/update operation will fail.
Note:The above
Warning!
is from SQL server depicting that the script was executed properly.
It looks like sqlcmd
doesn't like the variable $line
format.
Question: How to make $line
variable used with the while IFS= read -r line
statement workable/readable by sqlcmd
?