Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making curl send errors to stderr and everything else to stdout

Is there a way to tell curl to output errors to stderr, and everything else to stdout?

The reason is that I am using curl from the command line (actually a cronjob) to upload a file to an FTP site every evening. Unfortunately because curl outputs status information on stderr, I receive an e-mail about an error when nothing actually went wrong. (I'm redirecting stdout to a log file, but leaving stderr unchanged so that cron will e-mail it to me if there is any output.)

There are options to make curl silent, or output everything to stdout, however both these alternatives prevent errors from appearing on stderr - meaning I won't get an e-mail when there is actually an error I want to know about.

So is there a way to make curl only output errors on stderr, but leave normal output intact on stdout?

like image 707
Malvineous Avatar asked Aug 04 '11 00:08

Malvineous


2 Answers

Try this:

# No error messages because it succeeds. curl  http://www.shikadi.net/        --fail --silent --show-error  # This prints an error message to stderr curl  http://i.like.you.def.maybe/   --fail --silent --show-error 

Thanks to Russell Davis's answer on this page, man curl, and trial and error. For the curious, here is the wget version of the question: https://superuser.com/questions/420120/wget-is-silent-but-it-displays-error-messages

like image 149
dgo.a Avatar answered Sep 30 '22 14:09

dgo.a


curl -s -S

From the man page:

-s Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.

-S When used with -s it makes curl show an error message if it fails.

like image 30
Timmah Avatar answered Sep 30 '22 14:09

Timmah