crontab中的变量? [英] Variables in crontab?

查看:914
本文介绍了crontab中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在crontab中存储变量?我知道它不是外壳,但说我想要一些常量,像一个路径,我的应用程序或东西。

How can I store variables in my crontab? I realize it's not shell but say I want to have some constants like a path to my app or something?

想法?

推荐答案

在Vixie cron中,这可能是最常见的,你可以做一个shell脚本。

In Vixie cron, which is possibly the most common, you can do this almost exactly like a shell script.

VARIABLE=value
PATH=/bin:/path/to/doathing
0 0 * * * doathing.sh $VARIABLE

手册页说:


crontab中的行将是环境设置或cron命令。环境设置的形式为

An active line in a crontab will be either an environment setting or a cron command. An environment setting is of the form,

     name = value

其中等号(=)周围的空格是可选的,值中的任何后续非前导空格都将是分配值的一部分
到名称。值字符串可以放在引号(单或双,但匹配)中,以保留前导或尾随空白。名称
字符串也可以放在引号(单或双,但匹配)中以保留前导,尾随或内部空格。

where the spaces around the equal-sign (=) are optional, and any subsequent non-leading spaces in value will be part of the value assigned to name. The value string may be placed in quotes (single or double, but matching) to preserve leading or trailing blanks. The name string may also be placed in quote (single or double, but matching) to preserve leading, trailing or inner blanks.

您可以通过检查 crontab 的手册页来判断您是否拥有Vixie cron;作者将是Paul Vixie。不同的cron可能支持或可能不支持(BusyBox的cron,例如,不),在这种情况下,你最好的选择是将你的命令包装在shell脚本中,并从cron运行该脚本。事实上,对于任何复杂的事情,这是一件好事。

You can tell if you have Vixie cron by checking the man page for crontab; the author will be Paul Vixie. Different crons may or may not support this (BusyBox's cron for example, does not), in which case your best option is to wrap your command in a shell script and run that script from cron instead. In fact, this is a good thing to do for anything complicated.

这篇关于crontab中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆