简体   繁体   English

Shell脚本循环中的sqlcmd

[英]sqlcmd in shell script loop

Hi I have a shell script that inserts disk status of linux servers in SQL server. 嗨,我有一个Shell脚本,可在SQL Server中插入Linux服务器的磁盘状态。 Before inserting the SQL command, the program executes and ends properly. 在插入SQL命令之前,程序将正确执行并结束。 However, when I inserted the SQL command, the .sh file never goes to the next line to execute. 但是,当我插入SQL命令时,.sh文件永远不会转到下一行来执行。 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. 在我的bash脚本中,我在while循环中有sqlcmd,该循环将一遍又一遍地继续运行列表中的第一个项目,而不继续进行下一个项目。 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. 如注释中所述,将此< /dev/null到sqlcmd行的末尾将使它脱离循环中的阻塞点,并继续进行下一个tiem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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