We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

[resolved] crontab: being executed but no output



  • Dear all,

    I have an issue with crontab. I have following file
    #min hour day month dayofweek command
    */2 * * * * sudo python /root/py/dht.py
    */2 * * * * sudo date >> /root/ct.test
    and have restarted and enabled the service using
    /etc/init.d/cron start
    /etc/init.d/cron enable
    but no results of the scripts to be seen :-(.

    logread shows the following output
    Fri Nov 4 20:12:00 2016 cron.info crond[2154]: USER root pid 2378 cmd sudo python /root/py/dht.py
    Fri Nov 4 20:12:00 2016 cron.info crond[2154]: USER root pid 2379 cmd sudo date >> /root/ct.test
    Fri Nov 4 20:14:00 2016 cron.info crond[2154]: USER root pid 2390 cmd sudo python /root/py/dht.py
    Fri Nov 4 20:14:00 2016 cron.info crond[2154]: USER root pid 2391 cmd sudo date >> /root/ct.test

    so I would expect that the cron job is actually being executed as defined.

    ?? But why do I not get the result of the scripts / commands being run ?? If I run them from command prompt I get what I would expect...

    I am confused and have not been able to find anything on the web/in the forum on this. Might be that I not scanning for the right term, so any input would be appreciated.

    thanks a lot,
    GoSch



  • @gosch Though you don't say what you expect to see from the run of the crontab jobs, I suspect that they are outputting to stdout (and/or stderr). When crontab runs a job these output files are normally emailed to the crontab owner (see http://unix.stackexchange.com/questions/40623/where-does-the-output-go-from-at-and-cron-jobs). So, you have two options:

    1. Look in /var/log/syslog to see if this gives any info about (attempts to) mail the output

    2. Change your crontab commands to redirect stdout (and/or stderr) to known files. E.G. change your crontab commands to something like:

      • */2 * * * * sudo python /root/py/dht.py 1>>/root/dht.py.out 2>>/root/dht.py.err
      • */2 * * * * sudo date >> /root/ct.test 1>>/root/ct.test.out 2>>/root/ct.test.err

      And you should see the output grow in each of the named files each time the job is run



  • @Kit-Bishop: THANK YOU - you saved my day ;-)!!!

    1. Look in /var/log/syslog to see if this gives any info about (attempts to) mail the output

    no data to be found here.

    1. Change your crontab commands to redirect stdout (and/or stderr) to known files. E.G. change your crontab commands to something like:
      • */2 * * * * sudo python /root/py/dht.py 1>>/root/dht.py.out 2>>/root/dht.py.err
      • */2 * * * * sudo date >> /root/ct.test 1>>/root/ct.test.out 2>>/root/ct.test.err

    this was the game changer! generating the error log showed that sudo is the problem! command not found and therefore the scripts did no run :rolling_eyes: !

    To be complete:

    • dht.py is a simple python script that reads a DHT22 sensor and uploads the values to a webpage.
    • sudo date >> /root/ct.test had no other purpose than to see if the cron-demon is actually executing (was before I was aware of the logread command).

    thanks again - need to remember this!!

    best regards,
    GoSch



  • @gosch said in [resolved] crontab: being executed but no output:

    this was the game changer! generating the error log showed that sudo is the problem! command not found and therefore the scripts did no run :rolling_eyes: !

    A cron job runs in a world of its own where the environment might not be initialized as one might think, more precisely, the PATH environment variable. So, to be sure that your commands are always found, never use relative paths. Always use an absolute path to EVERYTHING, both commands and files. For example
    /bin/sudo /bin/date >> /root/ct.test

    PS: Not sure about the exact sudo and date directory for the Omega, check it out yourself, but that is the main idea for such use.



  • @fossette said in [resolved] crontab: being executed but no output:

    PS: Not sure about the exact sudo and date directory for the Omega, check it out yourself, but that is the main idea for such use.

    In openWRT/onion-os, sudo is not installed ... so, if you type this command you get the "not found error ... " it is not about missing path it is about missing command.

    Mor infos about more security read https://wiki.openwrt.org/doc/howto/secure.access#allow_temporary_privileged_access_using_sudo

    It exists but has to be installed .. opkg install sudo



  • @fossette & @Luciano-S

    thanks both for your input.
    @fossette: I'm clear about the potential of screewing up a cron-job due to relative paths, but as pointed out (and as explained by @Luciano-S being a standard-not-installed-on-openWRT-command) the missing sudo command was the problem.


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.