Cron job not running

  • Hello. I've been reading and tinkering for days but I still can't seem to get this cron job working. It's hopefully a simple fix and I'm just being stupid.

    I am trying to use crontab to run a script every 3 hours to download an EPG for TVheadend.

    To start, I used "crontab -e" to edit my crontab file. This is the crontab file I started with:

    Code
    0 0,3,6,9,12,15,18,21 * * * /storage/epg.sh

    I included an empty line at the end of the file as some posts recommended. I ^o to save the file as "/storage/.cache/cron/crontabs.753" and ^x to exit the editor. Next I run "crontab -l" which returns the file I just wrote.

    In my "/storage/" directory I have "epg.sh" which I have made executable with "chmod +x epg.sh" (I have also tried "chmod 775 epg.sh" and "chmod a+x epg.sh").

    This is my "epg.sh" file:

    Bash
    #!/bin/sh
    wget -O /storage/xmltv.php.xml "<url>"

    This runs perfectly when I do "sh /storage/epg.sh" in console, but it never runs through my crontab command.

    I've read a bunch of posts about cron and crontab on libreelec and far too many other linux systems.

    Following other's advice, I tried modifying my crontab file to this:

    Code
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/storage
    0 0,3,6,9,12,15,18,21 * * * /storage/epg.sh

    No luck.

    I also tried modifying my "epg.sh" to this:

    Bash
    #!/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/storage
    wget -O /storage/xmltv.php.xml "<url>"  

    Again, nothing.

    I've run "ps aux | grep cron", "ps aux | grep crond" & "ps aux | grep crontab" which return:

    Code
    # ps aux | grep cron
      619 root       0:00 /sbin/crond -f -S
      875 root       0:00 grep cron
    # ps aux | grep crond
      619 root       0:00 /sbin/crond -f -S
      877 root       0:00 grep crond
    # ps aux | grep crontab
      879 root       0:00 grep crontab

    This means they are all running, right? Hopefully they are all stopped and I'm being stupid and someone can tell me how to start them.

    I have tried "systemctl restart cron", which executes successfully but makes no difference.

    I have tried "/etc/init.d/crond start", "/etc/init.d/crond stop" & "service crond restart" based on random posts regarding other systems, obviously none of these execute.

    I even did "crontab -r" and made a brand new file with "crontab -e" again just to make sure I didn't mess something up the first time, but still no luck.

    I am at a loss. Does anyone have any sage advice for me? Please?

    Thanks in advance.

  • Could You just try to add 'bash' command to Your crontab:

    i.e.

    Code
    0 0,3,6,9,12,15,18,21 * * * bash /storage/epg.sh

    That shouldn't be necessary but might help...

  • What does systemctl status cron -l returns?

    Hello vpeter, "systemctl status cron -l" was returning:

    I tried adding "bash" to my crontab file as Jocke.Sve recommended. After that edit "systemctl status cron -l" is returning:

    Thanks for the useful command vpeter and for the suggestion Jocke.Sve! That seems to have gotten my cron job running.

    Now I just have to figure out why my wget is throwing a bad request error, despite working perfectly the other day.


    To anyone searching for a solution to crontab not running a shell script, try Jocke.Sve's advice:

    Change * * * * * /path/script.sh to * * * * * bash /path/script.sh

    If anyone stumbles upon this thread regarding "wget: server returned error: HTTP/1.1 400 Bad Request" make sure you don't have an empty line at the end of your script.

    Edited once, last by robertlabla (June 22, 2017 at 10:05 PM).