问题描述
我想运行这个语句:
curl 'http://localhost:8983/solr/dataimport?command=full-import'
每 10 分钟使用一次 CRON 作业.
every 10 minutes using CRON jobs.
我如何实现这一目标?
推荐答案
类似:
crontab <<'EOF'
SHELL=/bin/bash
#min hr md mo wkday command
*/10 * * * * curl 'http://localhost:8983/solr/dataimport?command=full-import'
EOF
之后使用 crontab -l
来查看它.但是,向 curl
命令添加一个选项,将输出放在特定的地方,因为它可能运行在您没有写访问权限的地方.此外,如果 curl
出现异常,您可能需要指定其完整路径,例如 /usr/bin/curl
,或设置 crontab
路径变量.
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.
EOF
周围的引号可防止替换 HEREIS 文档的内容(<<EOF
和 EOF 之间的所有内容).HEREIS 文档是 shell 功能,不是
crontab` 的一部分.
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`.
请参阅 man 5 crontab
以了解 crontab 文件中内容的详细分类.
See man 5 crontab
for a detailed breakdown of what goes in crontab files.
我通常会保留一个 ~/.crontab
文件以使用特殊的第一行进行编辑,并设置执行位:
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.]
这让我可以编辑我的 ~/.crontab
然后运行它:
This lets me edit my ~/.crontab
and then just run it with:
$ vi ~/.crontab
$ ~/.crontab
(我通常也会在它们上面添加扩展名以表明它们适用于哪个主机,例如 ~/.crontab.bigbox)
(I also usually have extensions on them to indicate which host they're for, like ~/.crontab.bigbox)
这篇关于使用 CRON 作业运行 curl 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论