pfSense cron作业未运行或没有输出

时间:2016-08-07 05:39:17

标签: cron pfsense

希望有人可以帮助我。

我写了一个python脚本,我想每隔5分钟在CRON下运行一次。 为了与最小特权的一般安全实践保持一致,我:

  • 创建了一个用户“自定义”以用于自定义脚本
  • 创建了一个“自定义”组(不希望任何东西在没人的情况下运行) 访问)和;
  • 将脚本(监视器)放在/ home / custom / bin

脚本中的shebang是:

#!/ usr / bin / env python2.7

授予用户自定义的唯一权限是:

Inherited from   Name   Description                  Action
                User - System: Shell account access   Indicates whether the user is able to login for example via SSH.

无论当前工作目录如何,都可以从命令行使用命令 / home / custom / bin / monitor 运行脚本。

我尝试使用cd / first来确保它不是路径问题,并且脚本正确运行。

该脚本在第一次运行时写入2个文件,后续运行附加到目录/ home / custom / bin / mondata中的那些文件

我安装了CRON包并创建了以下条目:

* / 5 * * * * custom / home / custom / bin / monitor

(似乎没有“应用更改”,所以我假设我不需要重新启动或做任何事情来加载更改。) (以上条目和许多其他条目都显示在WebGUI中,我知道其他几个cron作业正在运行。)

在等待足够的时间让脚本运行后,我检查了输出,但没有任何内容。

将自定义更改为root用于测试目的(以防问题是权限问题)无法解决问题。

以下是相关的文件权限:

[2.3.2-RELEASE][custom@local]/home/custom/bin: ls -laR ~
total 52
drwxr-xr-x  4 custom  nobody   512 Aug  7 00:14 .
drwxr-xr-x  4 root    wheel    512 Jul 27 15:24 ..
drwxr-xr-x  3 custom  custom   512 Aug  7 00:14 bin

/home/custom/bin:
total 20
drwxr-xr-x  3 custom  custom   512 Aug  7 00:14 .
drwxr-xr-x  4 custom  nobody   512 Aug  7 00:14 ..
drwxrwx---  2 custom  custom   512 Aug  7 00:07 mondata    <-Script output goes here
-rwxr-xr-x  1 custom  custom  4663 Aug  5 22:44 monitor    <-The script

/home/custom/bin/mondata:
total 8
drwxrwx---  2 custom  custom  512 Aug  7 00:07 .           <-NO OUTPUT! (I deleted the files manually after successful tests)
drwxr-xr-x  3 custom  custom  512 Aug  7 00:14 ..

我检查了以下错误消息:状态/系统/日志/系统/常规 - 找不到任何内容。

我甚至尝试暂时将/ home / custom / bin / mondata上的权限更改为777并将cron用户设置为root (仅用于测试的完全不可接受的安全实践,但即使这样也不起作用。)

我无法知道脚本是否正在运行,并且由于某种原因文件写入被拒绝,或者脚本根本没有运行。

BTW,cron选项卡在哪里?当我以root身份运行crontab -l时,我得到crontab:没有用于root的crontab,但我知道cron作业正在运行。 (我每天都有邮件报告。)

任何建议 - 即使是故障排除以了解脚本是否正在运行都会有所帮助。

感谢。

1 个答案:

答案 0 :(得分:0)

问题是python没有执行。

所谓的便携式&#34;在命令行工作的shebang -

#!/usr/bin/env python2.7

- 从cron不工作。

我将以下文件创建为/ home / custom / bin / tcron

#!/usr/bin/env python2.7
import os
os.system('/usr/local/bin/minicron')

从命令行运行时,它会在每次运行时将minicron错误放入日志中,但在从cron运行时不执行任何操作。

我将#!/ usr / bin / env python2.7更改为#!/ usr / local / bin / python2.7,现在它可以正常工作。

我不知道这是否故意#!/ usr / bin / env python2.7不能从cron工作,但是现在我不会担心它。

我希望通过记录这可能会为其他人带来同样的麻烦,如果它是一个应该报告的错误,那么知道如何做的人就会这样做。

相关问题