简体   繁体   English

Linux权限执行脚本

[英]Linux permissions executing script

Question is about sudo&cron I have 2 servers: 问题是关于sudo&cron我有2台服务器:

srv0 srv0
- I auth by .ppk and login name -我通过.ppk和登录名进行身份验证
- I run by hand simple .py script with sudo. -我使用sudo手动运行简单的.py脚本。
- Script runs command to webservice and prints to file time+returned datas(tuple). -脚本运行到Web服务的命令,并打印到文件时间+返回的数据(元组)。 It also runs well by cron, which was the aim 通过cron也可以很好地运行,这是目标

srv1 diff srv1差异
- I auth by root password -我通过root密码进行身份验证
- I can run script by hand without sudo and it works well -我无需sudo即可手动运行脚本,效果很好
- Cron runs it well, but prints to file just time. -Cron可以很好地运行它,但是可以立即打印到文件中。 It didn't execute command... It sends empy body message to /var/spool/mail/root 它没有执行命令...它向/ var / spool / mail / root发送empy正文消息

Extras: 附加功能:
- /home/monitors, 2 files(.py, log) are 777 at both servers -/ home / monitors,两个服务器上的2个文件(.py,日志)均为777

whats the problem with cron at srv1? srv1的cron有什么问题? Maybe in fileOpen? 也许在fileOpen中?

import string
import commands
import time

namesStr ='currtime;wrs-checklist-create;wrs-checklist-delete;wrs-checklist-getall;wrs-checklist-getone;wrs-checklist-update;wrs-photo-queue;wrs-shop-getall;wrs-template-getall;wrs-xauth-authenticate;'

getmess = commands.getstatusoutput('rabbitmqctl list_queues messages')
getmess = list(getmess[1].split('\n'))

messStr = ''
nixtime = str(int(time.time()))

for mess in getmess:
        messStr += mess + ';'

logQue = open('/home/monitors/logQue', 'a')
print >> logQue, nixtime + messStr
logQue.close()

In the crontab, before you command, add . 在crontab中,在命令之前添加。 $HOME/.bash_profile. $ HOME / .bash_profile。 For example: 例如:

0 5 * * * . 0 5 * * *。 $HOME/.profile; $ HOME / .profile; /path/to/command/to/run / path / to / command / to / run

Cron knows nothing about your shell; Cron对您的外壳一无所知。 it is started by the system, so it has a minimal environment. 它是由系统启动的,因此它具有最小的环境。 If you want anything, you need to have that brought in yourself. 如果您想要任何东西,则需要将其带入自己。

OR 要么

just change line 换线

getmess = commands.getstatusoutput(' rabbitmqctl list_queues messages') getmess =命令.getstatusoutput(' rabbitmqctl list_queues消息')

to

getmess = commands.getstatusoutput(' /usr/sbin/rabbitmqctl list_queues messages') getmess =命令.getstatusoutput(' / usr / sbin / rabbitmqctl list_queues消息')

which rabbitmqctl helps you find path to rabbitmqctl 哪个Rabbitmqctl可以帮助您找到Rabbitmqctl的路径

PS 聚苯乙烯

Sorry for my English (: 对不起我的英语不好 (:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM