简体   繁体   中英

sqlcmd in shell script loop

Hi I have a shell script that inserts disk status of linux servers in SQL server. Before inserting the SQL command, the program executes and ends properly. However, when I inserted the SQL command, the .sh file never goes to the next line to execute. It is always in a loop. Kindly help

#!/bin/bash

#Functions here
insert() {
echo "--INSERT FUNCTION--"
echo "$1"

fsname=$1
fs=$(echo "${fsname: -3}")

 sqlcmd -S <ipadd> -U <user> -P <pass> -d tech_admin -Q "EXEC insertDiskStatus $fs"
sleep 1

}
echo "TEST"
cd ~/Documents
pwd
df -Ph --exclude-type=tmpfs --exclude-type=ext3 --block-size=GB | column -t |         sed 1d > diskspace.log
filename=diskspace.log

while read -r line
do
 this=$line

 fs=$(echo $line | awk '{print $1}')

 insert $fs 

done < "$filename"

I had the same problem. In my bash script, I have sqlcmd in a while loop and the loop would continue running the first item in the list over and over and not continue on to the next item. As mentioned in the comments, adding this < /dev/null to the end of sqlcmd line will cause it to get out of stuck spot in the loop and carry on to the next tiem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM