开发者

How can I keep curl output out of mail from my cronjob?

I have written a Perl script that runs as a daily crontab job that uploads files to Amazon S3 via CURL. I want the output of the cron job emailed to me which works fine but I don't want that email to include messages related to the CURL upload (only those message my script is outputting). Here are the CURL related messages I'm seeing in the daily email right now:

  开发者_如何学编程% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0  230M    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0  230M    0     0    0  544k      0  1519k  0:02:35 --:--:--  0:02:35 1807k
  0  230M    0     0    0 1744k      0  1286k  0:03:03  0:00:01  0:03:02 1342k
  1  230M    0     0    1 2880k      0  1219k  0:03:13  0:00:02  0:03:11 1250k
  1  230M    0     0    1 4016k      0  1198k  0:03:17  0:00:03  0:03:14 1218k
  2  230M    0     0    2 5168k      0  1186k  0:03:19  0:00:04  0:03:15 1202k
  2  230M    0     0    2 6336k      0  1181k  0:03:19  0:00:05  0:03:14 1157k
  3  230M    0     0    3 7488k      0  1177k  0:03:20  0:00:06  0:03:14 1147k
  3  230M    0     0    3 8592k      0  1167k  0:03:22  0:00:07  0:03:15 1142k
  4  230M    0     0    4 9744k      0  1166k  0:03:22  0:00:08  0:03:14 1145k
  4  230M    0     0    4 10.6M      0  1163k  0:03:23  0:00:09  0:03:14 1142k
  5  230M    0     0    5 11.7M      0  1161k  0:03:23  0:00:10  0:03:13 1140k
  5  230M    0     0    5 12.8M      0  1158k  0:03:23  0:00:11  0:03:12 1133k
  6  230M    0     0    6 13.9M      0  1155k  0:03:24  0:00:12  0:03:12 1138k
  6  230M    0     0    6 15.0M      0  1155k  0:03:24  0:00:13  0:03:11 1138k
  7  230M    0     0    7 16.1M      0  1152k  0:03:25  0:00:14  0:03:11 1131k
  7  230M    0     0    7 17.2M      0  1152k  0:03:25  0:00:15  0:03:10 1132k
  7  230M    0     0    7 18.4M      0  1152k  0:03:24  0:00:16  0:03:08 1140k

I am using a simple Perl system() call to invoke CURL. Does anyone know what command line argument I can supply CURL to turn off the reporting of the upload progress?


There are a few options here.

You can use the -s or --silent flag to silence all output. From the curl manpage:

  -s/--silent
         Silent  or  quiet  mode. Don’t show progress meter or error mes-
         sages.  Makes Curl mute.

Or, rather than using something like system in your Perl script to run curl, you could use backticks or the qx operator to capture the output to a variable.

Or, you could open your curl process with a pipe to capture its STDOUT and look at it later.

Finally, you might want to explore replacing your system calls to curl with a native Perl library like LWP::UserAgent or Mechanize.


For some reason my version of CURL wasn't recognizing the -s or --silent which I know makes no sense. As @Friedo suggested I tried using backticks or the qx operator which also didn't get rid of unwanted upload progress reporting. Ultimately I went the very unelegant route of adding >/dev/null 2>&1 to the end of the system call which resolved the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜