How to check for a value after curl or wget?

2

I need to curl/wget a page and make sure it returned a particular value (else return 1), something like this:

curl http://example.com/something/run | grep -e '^success!$' || return 1

Which flags should I use in curl or wget? It's not working.

ChocoDeveloper

Posted 2013-02-05T06:28:29.990

Reputation: 2 327

Answers

2

You need to suppress the error output from curl with 2> /dev/null. Then, pipe the output to grep -qc, which will suppress normal output and just display the count of matches.

You can then proceed as usual.

curl "http://example.com" 2> /dev/null | grep -qci -e 'something' && echo "yay"

slhck

Posted 2013-02-05T06:28:29.990

Reputation: 182 472