Run a curl command using CRON jobs

前端 未结 3 448
孤城傲影
孤城傲影 2021-01-02 06:31

I want to run this statement:

curl \'http://localhost:8983/solr/dataimport?command=full-import\'

every 10 minutes using CRON jobs.

相关标签:
3条回答
  • 2021-01-02 06:50

    Something like:

    crontab <<'EOF'
    SHELL=/bin/bash
    #min hr md mo wkday command
    */10 *  *  *  *     curl 'http://localhost:8983/solr/dataimport?command=full-import'
    EOF
    

    Use crontab -l to get a look at it afterwards. BUT, add an option to that curl command to put the output somewhere specific, since it might be run somewhere to which you don't have write access. Also, if curl is anywhere unusual, you may need to specify its full path, like /usr/bin/curl, or set the crontab PATH variable.

    The quotes around EOF prevent substitution in the contents of the HEREIS document (everything between the <<EOF and EOF). HEREIS documents are a shell feature, not part ofcrontab`.

    See man 5 crontab for a detailed breakdown of what goes in crontab files.

    I usually keep a ~/.crontab file to edit with a special first line, and the execute bit set:

    #!/usr/bin/env crontab 
    SHELL+/bin/sh
    [... etc.]
    

    This lets me edit my ~/.crontab and then just run it with:

    $ vi ~/.crontab
    $ ~/.crontab
    

    (I also usually have extensions on them to indicate which host they're for, like ~/.crontab.bigbox)

    0 讨论(0)
  • 2021-01-02 06:53

    In case of using Cpanel :
    Cpanel->Cron Jobs->Put Time Interval(*/10 * * * * )
    Add command in the text box:
    curl -s "http://localhost:8983/solr/dataimport?command=full-import"
    where -s stands for silent (no output)
    You are done

    0 讨论(0)
  • 2021-01-02 07:08

    For blue host and go daddy server:

    curl -s "http://localhost:8983/solr/dataimport?command=full-import"
    
    0 讨论(0)
提交回复
热议问题