【发布时间】:2015-12-05 07:25:57
【问题描述】:
我已经按照https://github.com/homer6/frequent-cron上的安装说明安装了frequent-cron。
我已根据自己的需要更改了 /etc/init.d/frequent_service/init_script.tpl:
# This is arbitrary. Change it to whatever you'd like.
SERVICE_NAME="frequent_service"
# Frequent cron must exist at this path. Optionally, you can change it to a path where it does exist.
EXEC=/usr/bin/frequent-cron
# Change this to the path of your choice.
#PIDFILE=/var/run/${SERVICE_NAME}.pid
PIDFILE=/var/run/${Odoo_OPC}.pid
# Point this to the shell (or program) that you'd like to run. /tmp/myshell.sh is just an example.
#COMMAND=/tmp/myshell.sh
COMMAND=python /usr/bin/OPCConnectie/OdooNaarOPC.py
# Frequency is in milliseconds. The command will be invoked every frequency interval.
FREQUENCY=1000
但是当我想用以下方式启动频繁 cron 时:
sudo /etc/init.d/frequent_service start
它给出了这些错误:
hew@hew-VirtualBox:~$ sudo /etc/init.d/frequent_service start
/usr/bin/OPCConnectie/OdooNaarOPC.py: 1: /usr/bin/OPCConnectie/OdooNaarOPC.py: import: not found
/usr/bin/OPCConnectie/OdooNaarOPC.py: 2: /usr/bin/OPCConnectie/OdooNaarOPC.py: Syntax error: "(" unexpected
Starting frequent_service frequent cron...
/etc/init.d/frequent_service: 32: /etc/init.d/frequent_service: /usr/bin/frequent-cron: Permission denied
frequent_service started.
甚至之后:
sudo chmod -R 777 /usr/bin/OPCConnectie/
sudo chmod -R 777 /etc/init.d/frequent_service
它给出了相同的错误。
我想我可以把这个问题分成两个问题。
1) 关于python脚本的错误:
我不知道出了什么问题,因为它在正常的 cronjob 中运行良好。 我想如何在 init_script.tpl 中启动脚本有什么问题吗?
2) 错误权限被拒绝:
我一直认为 chmod -R 777 赋予文件夹 + 所有子文件夹和文件所有权限?那么为什么权限仍然被拒绝呢?
编辑:按照 exussum 建议检查权限:
hew@hew-VirtualBox:~$ namei -m /etc/init.d/frequent_service
f: /etc/init.d/frequent_service
drwxr-xr-x /
drwxr-xr-x etc
drwxr-xr-x init.d
-rwxrwxrwx frequent_service
hew@hew-VirtualBox:~$ namei -m /usr/bin/OPCConnectie/
f: /usr/bin/OPCConnectie/
drwxr-xr-x /
drwxr-xr-x usr
drwxr-xr-x bin
drwxrwxrwx OPCConnectie
这些是正确的吗?或者,这些权限是否足够?
编辑 2:对问题 1 的回答(python)
必须在 python 脚本的顶部添加以下行:
#!/usr/bin/env python
在这里找到:Crontab wont run python script
仍然需要 /usr/bin/frequent-cron 的权限。
【问题讨论】:
标签: linux permissions cron chmod