Tony
Tony

Reputation: 9581

curl in bash script vs curl one liner

This code ouputs a http status of 000 - which seems to indicate something didn't connect properly but when I do this curl outside of the bash script it works fine and produces a 200 so something with this code is off... any guidance?

#!/bin/bash

URLs=$(< test.txt | grep Url | awk -F\  ' { print $2 } ')
# printf "Preparing to check $URLs \n"
for line in $URLs
    do curl  -L -s -w "%{http_code} %{url_effective}\\n" $line
done

http://beerpla.net/2010/06/10/how-to-display-just-the-http-response-code-in-cli-curl/

Upvotes: 0

Views: 803

Answers (1)

doncoyote
doncoyote

Reputation: 11

your script works on my vt.

I added in a couple of debugging lines, this may help you to see where any metacharacters are getting in, as I would have to agree with the posted coments.

I've output lines in the for to a file which is then printed out with od. I have amended the curl line to grab the last line, just to get the response code.

#!/bin/bash

echo -n > $HOME/Desktop/urltstfile # truncate urltstfile

URLs=$(cat testurl.txt | grep Url | awk -F\  ' { print $2 } ')

# printf "Preparing to check $URLs \n"

for line in $URLs
    do echo $line >> $HOME/Desktop/urltstfile;
       echo line:$line:

     curl  -IL -s -w "%{http_code}\n" $line | tail -1
done

od -c $HOME/Desktop/urltstfile

#do curl  -L -s -w "%{http_code} %{url_effective}\\n" "$line\n"

Upvotes: 1

Related Questions