3

I am trying to log my curl output which looks as following: (which are randomly produced every 10th sec)

<RTW>
<RESULT>{ "Result": { "something1": 707,  "something2": { "array": ["95", "51", "65", "33", "95", "109", "87", "37", "49", "86"] } } }</RESULT>
<DISTRICT>{"0000":"City"}</DISTRICT>
</RTW>

My command is as following sh /path/to/script.sh 2>&1 | tee /path/to/logfile.txt

The issue is that I am not logging the original output I am logging some download statistics (which also shows up in the running terminal window). The following things are tracked in the download statistics:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   249    0   204  100    45    125     27  0:00:01  0:00:01 --:--:--   125
100   249    0   204  100    45     77     17  0:00:02  0:00:02 --:--:--    77

and so on..

How can I log (what I believe is the stdout) from the curl? I have tried changing the number in the 2>&1 section etc.

My curl command inside the script is as following: curl -k --data "objectID=ID&username=username&password=passwd" url -H "Header"

1
  • You're looking for -o file.txt. You should also consider reading the manual. Nov 9, 2016 at 16:38

3 Answers 3

2

You can make curl silent, no progress statistics (and error message will be shown), with the -s (--silent) option:

curl -s ...

From man curl:

-s, --silent

Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

3
  • Just tried that, no output data was shown in the file or in the terminal.
    – Chess
    Nov 9, 2016 at 16:23
  • @Chess This is the way to silent curl, if no output is being shown you need to look at your script/how you are doing things.
    – heemayl
    Nov 9, 2016 at 16:25
  • I will not deny that it is, but it is currently not what I was asking for. But thanks :)
    – Chess
    Nov 9, 2016 at 16:56
1

add | logger to the end of the curl command.

0

What worked for me to get the output of curl is to use the -s flag and assign curl's output to a variable.

Using the example you provided, the modification will be like:

RES="$(curl -k --data "objectID=ID&username=username&password=passwd" url -H "Header")"

#print the result

echo "$RES"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .