Home > Enterprise >  How do I extract only timestamp and date at my curl script?
How do I extract only timestamp and date at my curl script?

Time:04-12

I have this script that tests my connection and writes down status code. I want to extract date stamp and time on the top of it, every time it runs. Something like this:

Date and Time
result1
result2
result3

Date and Time
result1
result2
result3

My script looks like this:

while read LINE; do curl -o /dev/null --silent --head --write-out "%{http_code} $LINE\n" "$LINE"; done < /home/otto/Desktop/todo | tee >> /home/otto/Desktop/test_results.txt

I also want to add some spacing between results, because my current result log is this:

result1
result2
result3
result1 ---> I run the script again
result2
result3

Can anyone help?

CodePudding user response:

Try this:

(
  echo "• $(date -Is):"
  while read URL; do
    curl -o /dev/null --silent --head --write-out "  %{http_code} $URL\n" "$URL";
  done
) </home/otto/Desktop/todo | tee >>/home/otto/Desktop/test_results.txt
  • Related