Linux bash.sh 拒绝运行 cron 的权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21646551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission denied with bash.sh to run cron
提问by underscore
How to run a cron with bash script here.What i did as follows and here with errors.I want to know how to do that in ubuntu.I was struck with it now
如何在此处使用 bash 脚本运行 cron。我做了如下操作,此处有错误。我想知道如何在 ubuntu 中执行此操作。我现在对它感到震惊
bash.sh file
bash.sh 文件
#!/bin/bash
cd /var/www/Controller
/usr/bin/php post.php
In crontab -e
在 crontab -e
* * * * * /home/samitha/bash.sh >> /home/samitha/log/cron.log 2>&1
But now i getting following error
但现在我收到以下错误
/bin/sh: 1: /home/samitha/bash.sh: Permission denied
How will i fix it ? what i did wrong ?
我将如何修复它?我做错了什么?
采纳答案by MLSC
you can try the following solution as well:
您也可以尝试以下解决方案:
chmod +x post.php
chmod +x bash.sh
echo "* * * * * /home/samitha/bash.sh >> /home/samitha/log/cron.log 2>&1" >> cronjob
chmod +x cronjob
/etc/init.d/crond start #redhat based servers like centos
/etc/init.d/cron start #debian based servers like ubuntu
crontab cronjob
回答by Alex Jurado - Bitendian
The user executing that cron (the one who executes cron -e) doesn't have proper rights for executing that script. That is: either the script lacks the execution flag, or it's not possible to reach it because some of its ancestor directories lack the execution flag.
执行该 cron 的用户(执行 cron -e 的用户)没有执行该脚本的适当权限。也就是说:要么脚本缺少执行标志,要么无法访问它,因为它的某些祖先目录缺少执行标志。
回答by nesreka
The problem could be that your user does not have the rights to execute the file.
问题可能是您的用户无权执行该文件。
First you set the execution flag for your script
首先为脚本设置执行标志
chmod +x /home/samitha/bash.sh
Then you should check the permissions for the php file with
然后你应该检查php文件的权限
ls -lah /var/www/Controller
If neither your usergroup nor your username shows up, you have to run the script with superuser rights or change its permissions.
如果您的用户组和用户名均未显示,则您必须以超级用户权限运行脚本或更改其权限。
First way would be put your entry in
第一种方法是将您的条目放入
sudo crontab -e
or the second one would be (which I would not recommend, as everyone would be allowed to execute the script by calling your site)
或者第二个是(我不推荐,因为每个人都可以通过调用您的站点来执行脚本)
chmod a+x /var/www/Controller/post.php
回答by Hyperc0der
- File must be executable (@see chmod)
- All parent directories must have the execution flag (@see chmod)
- If crontab is running by different user i.e. not owner, maybe this user don't have rights to execute. (@see chown)
- 文件必须是可执行的(@see chmod)
- 所有父目录都必须有执行标志(@see chmod)
- 如果 crontab 由不同的用户(即不是所有者)运行,则该用户可能没有执行权限。(@see chown)