2

I calling an url using wget. This url gives me a response, its a Message id. I want to write the logs to a log file, with the message id as well. Also the log should be appended each time. I trying to do it in my shell script.

Is it possible to do this? If so how can i do it.

2
  • Did you already try using wget's --append-output=logfile (-a logfile) option? It looks like it is precisely what you would need.
    – Emeric
    Aug 4, 2015 at 6:58
  • @Emeric I have tried that it works fine for writing the output to the file. I also want the response to be written to the same file after the output. I need help with this.
    – Ace
    Aug 4, 2015 at 7:04

3 Answers 3

0
wget -O - $url --append-output=logfile >> logfile

Specifying - as filename for -O writes the output to stdout.

My shell does not hate using logfile for both append operations. It might work for you as well.

2
  • It works like a charm, Thanks, but is there a way to have the response after the output instead of the with the output.
    – Ace
    Aug 4, 2015 at 7:21
  • You can try using -nv, --no-verbose option. It reduces the -a part to a single line, but that single line can only be displayed after the requested contents have been retrieved (and therefore written to the logfile) since it also records whether the retrieval was successful.
    – Emeric
    Aug 4, 2015 at 14:49
0

I found a work around

wget --no-check-certificate -O contnt -a logfile $url
cat contnt >> logfile 
rm contnt

is there any other better way of doing this which doesnt include reading from the file and deleting the file?

0

You can do it like this:

wget - $url --server-response --append-output=logfile

You must log in to answer this question.

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