正确的方法使用cron来运行一个脚本? [英] Proper way to run a script using cron?
问题描述
在运行:用cron一个脚本,叫做内部的任何可执行文件必须有完整路径。我发现了这个尝试运行 wondershaper ,当许多错误表明,当它试图打电话给TC。所以我的问题是,什么是解决这个问题的正确方法?
When running a script with cron, any executable called inside must have the full path. I discovered this trying to run wondershaper, when many errors showed when it tried to call tc. So my question is, what's the proper way to overcome this problem?
可能的解决方案:
- cd到可执行文件夹和prepare符号链接到任何其他所谓的可执行文件有(不知道它的工作原理 - 低可移植性)
- 使用脚本(它的工作原理 - 在不同的发行版低的便携性)的完整路径
- 导出带所需的路径的路径变量脚本(如果不知道它的工作原理)在
那么,在此先感谢任何人帮助。
Well, thanks in advance for anyone helping.
推荐答案
您声明cron作业里面的变量是更明确,更易于维护:你必须修改包含在你的cron作业,你不需要传输多个文件,你应该将它移动到另一个系统。
Declaring variables inside your cron job is more explicit and easier to maintain : all you have to modify is contained in your cron job, and you don't need to transfer multiple files should you move it to another system.
PATH=/usr/bin:/your/fancy/dir
MYAPPROOT=/var/lib/myapp
*/2 * * * * myappinpath
*/3 * * * * $MYAPPROOT/mylocalapp
这篇关于正确的方法使用cron来运行一个脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!