Shell script read help

August 8, 2011 at 07:39:25
Specs: Windows 7
Using a unix command window (cygwin) I am running a shell script that reads some data from a file, then calls a curl command using the data read. This curl command prints some data about the data to the screen, and I want to write what was printed to a file. However I can't seem to read it, it just always reads the next data from the file I was originally reading from. Any ideas?

See More: Shell script read help

Report •

#1
August 8, 2011 at 08:38:04
Please post your code.

Report •

#2
August 8, 2011 at 08:47:28
value=0;

while read line
do
value=`expr $value + 1`;
echo $line;
curl -H "Accept:application/json" server/api/v1/tags?entity=/ip/$line?\&session_key=##### -k
echo
done < "ip_to_tag.txt"

original^

solved:

value=0;

while read line
do
value=`expr $value + 1`;
echo $line;
curl -H "Accept:application/json" server/api/v1/tags?entity=/ip/$line?\&session_key=##### -k >>outputfile.txt
echo
done < "ip_to_tag.txt"


Report •

#3
August 8, 2011 at 10:55:10
Not being familiar with the curl command, I can only make suggestions:

FIrst, I am assuming that if you remove the first while loop that you are still having trouble with the second loop redirecting to outputfile.txt?

Second, I would try placing double quotes around the second argument and see if that helps:

# untested
curl -H "Accept:application/json" ?server/api/v1/tags?entity=/ip/$line?\&session_key=##### -k" >>outputfile.txt

Third, if you still have trouble, maybe the shell is getting confused with all the double quotes. Try eval'ing the string:

# untested
eval curl -H "Accept:application/json" ?server/api/v1/tags?entity=/ip/$line?\&session_key=##### -k" >>outputfile.txt


Report •
Related Solutions


Ask Question