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

Follow

Comments

6 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
    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

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

    1
    Comment actions Permalink
  • 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

    0
    Comment actions Permalink
  • Avatar
    Alisa Kasyanova

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

    0
    Comment actions Permalink
  • Avatar
    Kathrin Neuwirth

    -: sleep: command not found

    I have tried /bin/sleep but then it says:

    -: /bin/sleep: No such file or directory

    0
    Comment actions Permalink
  • Avatar
    Taras Ermoshin

    Hello @Kathrin Neuwirth!

    The error is caused by the fact that the binary /bin/sleep is missing on the server with Plesk. It can be caused by one of the reasons below (though it's not the only possible reasons):

    1. Plesk is installed in a Docker container.
    2. Plesk is installed on a server with Windows Server operating system.

    To clarify the exact cause, please contact the server administrator or the provider of the server.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request