Crontab Permission Denied

I have a problem with crontab when I run the script.

My sudo crontab -e looks like this:

05 00 * * * /opt/mcserver/backup.sh 10 00 * * * /opt/mcserver/suspend.sh 05 08 * * * /sbin/shutdown -r +1 11 11 * * * /opt/mcserver/start.sh <--- This isn't working 

And start.sh looks like this:

 #!/bin/sh screen java -d64 -Xincgc -Xmx2048M -jar craftbukkit.jar nogui 

and have these permissions (ls -l output)

 -rwxr-xr-x 1 eve eve 72 Nov 24 14:17 start.sh 

I can run the command from the terminal using sudo or not

 ./start.sh 

But it does not start with crontab. If i do

 grep -iR "start.sh" /var/log 

I get the following output

 /var/log/syslog:Nov 27 11:11:01 eve-desk CRON[5204]: (root) CMD (eve /opt/mcserver/start.sh) grep: /var/log/btmp: Permission denied grep: /var/log/lightdm/x-0-greeter.log: Permission denied grep: /var/log/lightdm/lightdm.log: Permission denied grep: /var/log/lightdm/x-0.log: Permission denied 

So my question is: why doesn't it work? And since my script works without using sudo, do I have to enter it in sudo crontab?

(and I'm using Ubuntu 12.10)

Thanks in advance Philip

<h / "> Reply to twalberg answer

1. Owner changed to craftbukkit for root to make sure the problem is fixed.

 -rw-r--r-- 1 root root 12084211 Nov 21 02:14 craftbukkit.jar 

and also added an explicit cd to my start.sh script as such:

 #!/bin/sh cd /opt/mcserver/ screen java -d64 -Xincgc -Xmx2048M -jar craftbukkit.jar nogui 

2. I do not quite understand what you mean here. Should I use the following path in my start.sh file when java starts? (output from which java)

 /usr/bin/java 

3. When my server closes, the screen ends. In any case, is it nice to run the screen in "off mode"?

I still got the same "Failure Resolution" error.


The problem is solved ! Using the appropriate flag on the screen, as shown below, it now works as it should!

 screen -d -m java -d64 -Xincgc -Xmx2048M -jar craftbukkit.jar nogui 

Many thanks to those who responded, and especially twalberg!

+4
source share
3 answers

Here are some things to check:

  • root obviously has read / execute permissions on start.sh , but what permissions on craftbukkit.jar can root read? You can also add an explicit cd /path/to/where/craftbukkit.jar/is to your start.sh script.
  • Is java in root default path in cron ? Note that this path is not necessarily the same as the one you get through sudo , su or log in directly as the root user - it is usually much more limited. Use the full path names for java and craftbukkit.jar to get around this.
  • Since screen does not start with an available terminal, you may need screen -d -m ... We hope that you intend to eventually connect to each instance of screen and complete it later, or you agree to terminate it automatically when the script is executed ...
  • The entry /var/log/syslog shows that cron actually executed the script, so it should have failed for one of the above reasons (or something else I haven’t noticed yet)
  • Other errors from grep are explained only by the fact that your non- root does not have permission to read these specific files (this is normal and good).
+1
source

start.sh owned by "eve: eve" and your crontab is running as root.

You can solve this problem by running the following command

 chown root:root /opt/craftbukkit/start.sh 

Your crontab will work as root, but.

Tip: Absolute paths are always used when starting bash in crontab (this will make debugging easier).

+1
source

The log shows that the user does not have access to the dir "/ var / log /", you must set the permission for the log file for the cron owner.

0
source

All Articles