Getting Crontab to work (Debian 10)

Discussion in 'Systems Administration' started by DarkBoomba, Dec 24, 2019.

  1. Hi everyone,

    I'm running a spigot server on Debian 10 and I'm trying to get crontab to work. I've been all over the internet but have not found a working solution.

    So here is my situation, I currently have cron installed (for some reason only for root after reinstall). I have a shell script called reboot that I want to run every day at 3am. So I made a crontab like this:

    * 3 * * * /home/user/path/to/script/reboot

    I've made the script executable by doing chmod +x reboot. But it still doesn't work.
    At first I tried with a script called reboot.sh but I read that the .sh extension could cause some troubles so I tried without (no luck obviously).

    I'm completely lost as to how to get it working. I'd appreciate any help!
    Thanks for reading!

    - DarkBoomba
     
  2. Phoenix616

    Resource Staff

    Your script is not a program, you need to specify which program you want to execute it with. In the case of an sh script you need to execute it with the program which's scripting language you used in the script, in this case I assume either sh or bash. Just put that in front of the file path to make cron execute your script with (ba)sh.
     
  3. Hey thanks for your response. It is running with /bin/sh indeed. I added it in front of the script but still no luck. The line currently is
    * 3 * * * /bin/sh /path/to/script/reboot

    Any clue why this wouldn't work?
     
  4. You have to clarify which part doesn't work.

    Running the crontab, or running the shell script.

    What does /var/log/cron.log say that's going on when it attempts to run it.
     
  5. Sorry about that. The script works fine on its own. The crontab just doesn't run.

    /var/log/cron.log seems to be empty.

    "grep CRON /var/log/syslog" seems to say it is running the script, but it doesn't.
    This is what it says:

    Code (Text):
    Dec 26 22:01:01 MCSERVER CRON[81638]: (root) CMD (/bin/sh /path/to/script/reboot)
     
    The path to script is correct. I'm not the best with Debian (obviously).

    Thanks for helping out :)
     
  6. foncused

    Moderator Patron

    Are you restarting cron when you update crontab?
    Code (Bash):
    sudo service cron restart
    I would think this should work (3:00am) (replace 'user' with username):
    Code (Bash):
    0 3 * * * user /home/user/path/to/script/./reboot.sh