使用 CRON 作业运行 curl 命令

编程入门 行业动态 更新时间:2024-10-25 00:28:09
本文介绍了使用 CRON 作业运行 curl 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行这个语句:

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 文档的内容(<<EOFEOF 之间的所有内容).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 ofcrontab`.

请参阅 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:关键词]

本文发布于:2023-03-27 04:35:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/678948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   命令   CRON   curl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!