Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect curl output to stdout and log files

Tags:

bash

curl

How do i get curl output on both stdout and log files?

This will redirect to log files.

curl -o $OUTPUTFILE 2>>$LOGFILES $url

And this will show output on stdout.

curl -o $OUTPUTFILE $url
like image 416
Antarus Avatar asked Jun 25 '13 09:06

Antarus


People also ask

How do I redirect a curl output to a file?

For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command. Example: curl https://www.google.com/robots.txt | pbcopy . This will copy all the content from the given URL to your clipboard.

Does curl write to stdout?

When asking curl to get a URL it'll send the output to stdout by default. You can of course easily change this behavior with options or just using your shell's redirect feature, but without any option it'll spew it out to stdout.

How do I save a curl script?

We can save the result of the curl command to a file by using -o/-O options. Now the page gettext. html will be saved in the file named 'mygettext.

Where does curl write to?

OUTPUT top If not told otherwise, curl writes the received data to stdout. It can be instructed to instead save that data into a local file, using the -o, --output or -O, --remote-name options. If curl is given multiple URLs to transfer on the command line, it similarly needs multiple options for where to save them.


1 Answers

You use tee:

curl -o $OUTPUTFILE $URL 2>&1 | tee $LOGFILE 
like image 51
brice Avatar answered Oct 13 '22 02:10

brice