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

Cron job



  • From another post on cron jobs.

    @Brad-Buskey said in Cron trouble:

    *     *     *   *    *        command to be executed
    -     -     -   -    -
    |     |     |   |    |
    |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
    |     |     |   +------- month (1 - 12)
    |     |     +--------- day of        month (1 - 31)
    |     +----------- hour (0 - 23)
    +------------- min (0 - 59)
    

    I also keep my crontab info in a text file in /root. Whenever I make a change, or want to add to it, all I need to do is edit the text file, then run the following:

    crontab /root/crontab.txt
    

    I always then verify it is there with

    crontab -l
    

    Then, you can restart crontab with

    /etc/init.d/crontab restart
    

    For me, this is easier and allows for cut/paste.

    My crontab is set for ever 20 minutes.

    */20 * * * * /smb/scripts/phpweather.sh
    


  • @Manuel-Godinez said in Cron job:

    tried running from the command line and got the following:

    root@Omega-AA00:/# /www/php/test.php
    /www/php/test.php: line 1: can't open ?php: no such file
    /www/php/test.php: line 3: include: not found
    /www/php/test.php: line 5: syntax error: unexpected "("

    Thanks again

    please show us at least your script line 1-5
    and i believe in /www/php/ you can't execute php?!



  • @Manuel-Godinez said in Cron job:

    tried running from the command line and got the following:

    root@Omega-AA00:/# /www/php/test.php
    /www/php/test.php: line 1: can't open ?php: no such file
    /www/php/test.php: line 3: include: not found
    /www/php/test.php: line 5: syntax error: unexpected "("

    Thanks again

    Didnt see this post, was replying to the one on the cron.

    PHP is not a shell scripting language, it is a web scripting language. you need to somehow invoke the webserver from the command line. I dont know if that is possible.

    May be better to convert the PHP code to something other than a webscript. Maybe SH or Python.



  • Thanks Brad and Luciano and Don,

    Guess going to have to learn another language šŸ˜ž



  • Nope, I just tried creating a .php with a simple command to call a shell script, and the ASH shell could not "run" the php file. It is not a shell executable scripting language, it needs a web interpreter in order to run, and has to be run from a browser.

    You will want to convert whatever the PHP page is doing into a script language the shell can process.



  • I was looking at the docs and they do mention the php-cli to be able to run from the command line but it works when I doit manually, but again, when using the cron it doesn't. So you think SH or Python would be easier for a PHP guy to grasp the basics?



  • @Manuel-Godinez What does crontab -l return when you run it on the command line? I dont think your crontab is set up right.



  • It does return the exact cron job:

    5 13 * * * /www/php/test.php > /tmp/test.log



  • Ok. I am now trying Python to run the cron script. I have done the following steps:

    1 - Upgraded to latest firmware b157
    2 - opkg update
    3 - opkg install python
    4 - opkg install python-light pyOnionGpio
    5 - did a reboot
    6 - got the following code into a filename called test2.py in the root folder :

    import time
    import onionGpio

    gpioNum = 18
    gpioObj = onionGpio.OnionGpio(gpioNum)

    set to output

    status = gpioObj.setOutputDirection(0)

    alternate the value

    loop = 1
    value = 0
    while loop == 1:
    # reverse the value
    if value == 0:
    value = 1
    else:
    value = 0

    # set the new value
    status  = gpioObj.setValue(value)
    print 'GPIO%d set to: %d'%(gpioNum, value)
    
    time.sleep(5)
    

    7 - chmod the test2.py to make it executable. 0744
    8 - Now I go to the crontab -e and inserted the following line:

    12 6 * * * /test2.py > /tmp/test.log 2>&1

    9 - restarted cron
    10- waiting to execute
    11 - got this at test.log :

    /test2.py: line 1: import: not found
    /test2.py: line 2: import: not found
    /test2.py: line 4: gpioNum: not found
    /test2.py: line 5: syntax error: unexpected "("

    So I am guessing for some reason, it didn't find the import file onionGpio.py but I checked already and it is in the location it is suppose to be which is /usr/lib/python2.7/

    I am wondering if I missed a step?

    Thanks again for all your help



  • @Manuel-Godinez

    In the cron aren't you missing the python call?
    So change to something like this, depending where test2.py is located

    12 6 * * * python /test2.py > /tmp/test.log 2>&1
    


  • Thank you Costas!! That was it. That should be it now. And thanks everyone else too for their help.



  • @Costas-Costas Thank for the help with Cron! Left out the python call too in my cron scrip.



  • @Brad-Buskey Thanks for the detailed help with Cron. Tried for hours, if not days, to try to get it setup in my Omega2+.


Log in to reply
 

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