使用CRON作业运行curl命令 [英] Run a curl command using CRON jobs
问题描述
我想运行这个语句 -
如何使用CRON作业每隔10分钟使用curl'http:// localhost:8983 / solr / dataimport?command = full-import'我要实现这个吗?
提前感谢。
类似:
crontab<'EOF'
SHELL = / bin / bash
#min hr md mo wkday命令
* / 10 * * * curl'http:// localhost:8983 / solr / dataimport?command = full-import'
EOF
$ b b
使用 crontab -l </ code>以后查看它。 ,向
curl
命令添加一个选项,将输出放在特定的位置,因为它可能运行在没有写入的地方访问。此外,如果 curl
是不寻常的,您可能需要指定其完整路径,例如 / usr / bin / curl
,或设置 crontab
PATH变量。
EOF
防止在HEREIS文档的内容中替换(<< EOF
和 EOF之间的所有内容)。 HEREIS文档是一个shell功能,不是
crontab的一部分。
请参阅 man 5 crontab
我通常保留一个〜/ .crontab
文件用特殊的第一行编辑,并设置执行位:
#!/ usr / bin / env crontab
SHELL + / bin / sh
[...等等]
我的〜/ .crontab
,然后运行它:
$ vi〜/ .crontab
$〜/ .crontab
他们指示他们的主机,如〜/ .crontab.bigbox)
Im a complete newbie when it comes to CRON so please bear with me.
I want to run this statement -
curl 'http://localhost:8983/solr/dataimport?command=full-import'
every 10 minutes using CRON jobs.
How do I achieve this? Thanks in advance.
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 of
crontab`.
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)
这篇关于使用CRON作业运行curl命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!