How to create a scheduled task to fetch URL every 15 seconds

Follow

Comments

4 comments

  • Avatar
    Marco Marsala

    I don't know if this is the right article where to ask that, but how to redirect the output to a file named with date and time of the run?

    curl --silent 'http://example.com' &> logs/$(date) 

    but trying to format the datetime will fail:

    curl --silent 'http://example.com' &> logs/`date +%F`
    curl --silent 'http://example.com' &> logs/$(date +%F)
    curl --silent 'http://example.com' &> logs/$(date +'%F %T') 

    /bin/sh: -c: line 0: unexpected EOF while looking for matching `)'
    /bin/sh: -c: line 1: syntax error: unexpected end of file
  • Avatar
    Alisa Kasyanova

    @Marco Marsala
    Hi! Add the "\" before the percent sign, like this: curl --silent 'http://example.com' &> logs/`date +\%F`

  • Avatar
    Marco Marsala (Edited )

    Better way, with a single scheduled task and a single sleep process:

    for i in {1..4}; do curl --silent "http://example.com" &>/dev/null; sleep 15; done

  • Avatar
    Alisa Kasyanova

    @Marco Marsala
    Thank you for your input! I have updated the article accordingly.

Please sign in to leave a comment.

Have more questions? Submit a request