2

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"
10
  • I tried to put return at the end of function, but it still continues to loop Commented Feb 11, 2015 at 1:15
  • What do you mean "continues to loop"? What happens exactly? Commented Feb 11, 2015 at 1:16
  • its stuck in sqlcmd... please help :( Commented Feb 11, 2015 at 1:18
  • never goes to the next line of command. Commented Feb 11, 2015 at 1:19
  • 1
    Does it work if you add < /dev/null to the sqlcmd line? Commented Feb 11, 2015 at 2:44

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this answer! any idea why sqlcmd is doing this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.