0

First- I've already scoured this page and nothing has worked.

My script will create a file, this is how I know if it has run or not. /var/log/syslog isn't giving me any debugging information. Below is my crontab section, below what's already there by default:

SHELL=/bin/bash

# Check for minecraft server updates
* * * * * root minecraft_update > /tmp/cron.out

# TEST
* * * * * root env > /tmp/env.out

Note: there is a blank line at the end of the crontab file. I specified the bash shell even though that is specified in my script. My script (minecraft_update) lives in the /usr/local/bin directory, and the only other commands it calls are grep, ls, and head, which are all in the /bin dir, which is already defined in the crontab PATH.

The /tmp/cron.out file is created, but empty. The /tmp/env.out file is created and confirms that the PATH includes both the /usr/local/bin and /bin dirs, and also confirms the SHELL=/bin/bash.

Addtl. perms info:

ll /etc/crontab
-rw-r--r-- 1 root root 998 Jul  1 12:47 /etc/crontab

ll /usr/local/bin/minecraft_update
-rwxr--r-- 1 root root 1132 Jul  1 12:31 minecraft_update*

I'm so frustrated with this! Please bring an end to my * * * * * misery... [That's cron notation, not profanity btw. Gotta love Linux humor :)]

  • I'd start by redirecting standard error to the file as well (i.e. minecraft_update > /tmp/cron.out 2>&1) - that might give you some indication of what's failing – steeldriver Jul 1 '17 at 17:19
  • It's still empty... – Willman Jul 1 '17 at 17:23
  • Your problem seems to be with the minecraft_update script, not cron nor crontab. – user535733 Jul 1 '17 at 19:11
  • But I can run the script just fine and it runs as expected. – Willman Jul 1 '17 at 19:12
  • Are you editing /etc/crontab directly, or are you using sudo crontab -e? (Which uses a different file) – pizzapants184 Jul 1 '17 at 22:30
1

You don't need 'root' in the crontab listing, (unless you have a program root that you are using to run your script).

If ypu are editing your crontab with sudo crontab -e (/var/spool/cron/crontabs/root), then you do not need a username. If you are editing the system-wide crontab (/etc/crontab), then you do need a username listed.

E.x.

sudo crontab -e

SHELL=/bin/bash

# Check for minecraft server updates
* * * * * minecraft_update > /tmp/cron.out

# TEST
* * * * * env > /tmp/env.out

OR nano /etc/crontab

SHELL=/bin/bash

# Check for minecraft server updates
* * * * * root minecraft_update > /tmp/cron.out

# TEST
* * * * * root env > /tmp/env.out

Source

  • You do need a user field (root by default) in the system-wide /etc/crontab file (which is what the OP appears to be using) - please see the EXAMPLE SYSTEM CRON FILE section of man 5 crontab – steeldriver Jul 1 '17 at 22:00
  • @steeldriver Sorry, thought 'sudo crontab -e' edited that by default. – pizzapants184 Jul 1 '17 at 22:22
  • 1
    I was editing /etc/crontab directly as root. Now that you mention it, I did read somewhere that using crontab -e was better, I'll try that. So crontab -e does not edit /etc/crontab? What file does it manipulate then? – Willman Jul 1 '17 at 23:37
  • @Willman crontab -e edits a file in the directory /var/spool/cron/crontabs named after the user, so sudo crontab -e edits /var/spool/cron/crontabs/root. Note that each file is run with the permissions of its respective user. – pizzapants184 Jul 1 '17 at 23:42
  • Nevermind, this is working now, thanks! For some reason, the file that was supposed to be written every time my script runs wasn't being detected by my watch -n 0.1 command on the dir.... But I confirmed a different way that it was working. Weird... – Willman Jul 2 '17 at 18:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.