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 :)]

Willman
  • 233
  • 1
  • 4
  • 12

1 Answers1

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

pizzapants184
  • 739
  • 8
  • 18
  • 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 01 '17 at 22:00
  • @steeldriver Sorry, thought 'sudo crontab -e' edited that by default. – pizzapants184 Jul 01 '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 01 '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 01 '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 02 '17 at 18:25