Results 1 to 7 of 7

Thread: Root crontab not running at all.

  1. #1
    Join Date
    Apr 2014
    Beans
    800

    Root crontab not running at all.

    The script works manually. On the root crontab it doesn't even run. Doesn't even enter the log that it tried or anything.

    Code:
    # cat root # DO NOT EDIT THIS FILE - edit the master and reinstall.
    # (/tmp/crontab.UoKMpI/crontab installed on Fri Aug 13 10:12:58 2021)
    # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
    MAILTO=""
    USER=root
    # m h  dom mon dow   command
    15 10 * * *	localbackups.sh
    Code:
    $ cat /var/log/cron.log
    Aug 13 10:12:55 homewrecker crontab[11208]: (root) BEGIN EDIT (root)
    Aug 13 10:12:58 homewrecker crontab[11208]: (root) REPLACE (root)
    Aug 13 10:12:58 homewrecker crontab[11208]: (root) END EDIT (root)
    Aug 13 10:13:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    And a couple minutes after it should have run.

    Code:
    Aug 13 10:12:55 homewrecker crontab[11208]: (root) BEGIN EDIT (root)Aug 13 10:12:58 homewrecker crontab[11208]: (root) REPLACE (root)
    Aug 13 10:12:58 homewrecker crontab[11208]: (root) END EDIT (root)
    Aug 13 10:13:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Code:
    # systemctl status cron
    ● cron.service - Regular background program processing daemon
         Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: >
         Active: active (running) since Fri 2021-08-13 07:22:47 MST; 2h 54min ago
           Docs: man:cron(8)
       Main PID: 851 (cron)
          Tasks: 1 (limit: 19015)
         Memory: 508.0K
         CGroup: /system.slice/cron.service
                 └─851 /usr/sbin/cron -f
    
    
    Aug 13 09:17:01 homewrecker CRON[6330]: pam_unix(cron:session): session opened >
    Aug 13 09:17:01 homewrecker CRON[6330]: pam_unix(cron:session): session closed >
    Aug 13 09:50:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 09:55:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 09:56:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 09:59:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 10:06:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 10:11:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 10:12:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    Aug 13 10:13:01 homewrecker cron[851]: (root) RELOAD (crontabs/root)
    I am thoroughly stumped. I've never seen this before.

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Root crontab not running at all.

    localbackups.sh needs to be the /full/path/to/the/script/localbackups.sh

  3. #3
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Root crontab not running at all.

    Start with an extremely simple script, that just echoes "I'm alive" to a log file. Call it with full path and use full path of programs called in the script (but if you use the shell's echo, you need no path). I suggest that you have a shebang in the beginning of the file, for example #!/bin/bash

    When the simple thing works, step up the complexity, for example a tool that needs root permissions, etc. Finally the whole backup system works.



    Comment: I don't quote the path, when setting it in my crontabs (and there are no spaces), maybe quoting prevents it from working for you.
    Last edited by sudodus; August 13th, 2021 at 08:09 PM. Reason: ninja'd about full path ;-P

  4. #4
    Join Date
    Apr 2014
    Beans
    800

    Re: Root crontab not running at all.

    I got an echo to pipe to a test file with and without full path. Nothing more complex though. Even a straight duplicity command (with or without full path) doesn't run. I went ahead and figured out a systemd timer though and it's working nicely every 2 hours. Much prefer the crontab method. Such is life. I'll keep tinkering.

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Root crontab not running at all.

    Quote Originally Posted by Tadaen_Sylvermane View Post
    I got an echo to pipe to a test file with and without full path. Nothing more complex though. Even a straight duplicity command (with or without full path) doesn't run. I went ahead and figured out a systemd timer though and it's working nicely every 2 hours. Much prefer the crontab method. Such is life. I'll keep tinkering.
    Almost all cron job failures are due to environment problems and assumptions. Assuming the script works from a shell, but not from cron, that just means that the output from env is very different under those two situations.
    Run
    env > /tmp/env-shell
    Then put /usr/bin/env > /tmp/env-cron into a crontab to run once.
    Now compare the two files. For a long time, HOME wasn't set which would routinely break things. Running stuff as root usually means all sorts of things aren't set. cron doesn't source ~/.bashrc, so none of those settings are made.

    And never trust the PATH in cron. Always fully specify the full path to every command used. Always.

  6. #6
    Join Date
    Apr 2014
    Beans
    800

    Re: Root crontab not running at all.

    You are correct on Environment. I just found it. I had a root check to run. Removing this allowed it to work.

    Code:
    if [ "$USER" = root ] ; then
    I'm not sure why that didn't work when I know I had USER defined in the crontab. At any rate, the script works quite nicely now via cron.

    Link to script as it sits - https://gitlab.com/jmgibson1981/home...ocalbackups.sh

    Marking solved.

  7. #7
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Root crontab not running at all.

    I wouldn't trust an environment variable to validate 'root'.
    I would use the /usr/bin/id -u command.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •