Cronjob troubles

Discussion in 'General' started by sjau, Mar 30, 2012.

  1. sjau

    sjau Local Meanie Moderator

    Hmmm, I tried to set a cron from ISPC but it does not seem to be run.

    Here are the settings:

    [​IMG]

    The content of the shell script is this:

    Code:
    root@manager /var/www/clients/client1/web9/web/urteile # cat /var/www/clients/client1/web9/web/urteile/cron.sh 
    #!/bin/bash
    
    curPath="/var/www/clients/client1/web9/web/urteile";
    
    php -f ${curPath}/bger_inital.php
    php -f ${curPath}/bverwg_inital.php
    php -f ${curPath}/bstger_inital.php
    php -f ${curPath}/sg_inital.php
    php -f ${curPath}/fr_inital.php
    php -f ${curPath}/email.php
    php -f ${curPath}/email_bverwger.php
    php -f ${curPath}/email_bstger.php
    php -f ${curPath}/email_sg.php
    php -f ${curPath}/email_fr.php
    
    Running the shell script from the terminal works fine but cron doesn't run it.
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Can you use the full path to the php binary in the script?
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    If this is a jailed cronjob, then the ath to the script is /web/urteile/cron.sh and in the jail, php cli is most likely not available.

    By the way, doing this as url cron would be much easier, url cron means that you run a httprequest by entering just the url in the cron command field:

    http://www.yourdomain.tld/web/urteile/cron.php

    and in the cron.php you add the other php files as includes or as url fopen.
     
  4. sjau

    sjau Local Meanie Moderator

    I try now using full path to the php binary.

    There's no cron.php but a bash script "cron.sh". it should be working from the command line. When running it in the shell it should work. I plan on moving those files outside the web dir anyway.
     
  5. sjau

    sjau Local Meanie Moderator

    I altered the cron.sh file to this:

    Code:
    
    #!/bin/bash
    
    main_function
    {
    
            curPath="/var/www/clients/client1/web9/web/urteile";
    
            /usr/bin/php -f ${curPath}/bger_inital.php
            /usr/bin/php -f ${curPath}/bverwg_inital.php
            /usr/bin/php -f ${curPath}/bstger_inital.php
            /usr/bin/php -f ${curPath}/sg_inital.php
            /usr/bin/php -f ${curPath}/fr_inital.php
            /usr/bin/php -f ${curPath}/email.php
            /usr/bin/php -f ${curPath}/email_bverwger.php
            /usr/bin/php -f ${curPath}/email_bstger.php
            /usr/bin/php -f ${curPath}/email_sg.php
            /usr/bin/php -f /var/www/web1/html/urteile/email_fr.php
    
    }
    
    if [ -z $TERM ]
    then
            # if not run via terminal, log everything into a log file
            main_function 2>&1 >> /var/www/clients/client1/web9/web/urteile/cron.log
    else
            # run via terminal, only output to screen
            main_function
    fi
    
    That should make a cron.log file when the script is called by cron. However, the script should have been called meanwhile but no .log file was created. So, cron doesn't run that script.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Please see my comments on paths in #3.If this is a jailed cronjob, then none of the paths (neither curPath nor the log path) exist from the view of the cronjob as the root of the jail is /var/www/clients/client1/web9/, so you have to use paths the are relative to that dir inside the script like:

    /web/urteile/cron.log

    instead of:

    /var/www/clients/client1/web9/web/urteile/cron.log

    You can see if the cronjob is jailed or not in the cron file in /etc/cron.d/

    Beside that. there is no php binary available in the jail, so you cant call php then (see #3).
     
  7. sjau

    sjau Local Meanie Moderator

    till:

    ok, it is jailed. How to unjail it?
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Change the shell in the cronjob config file in /etc/cron.d/ to /bin/bash and ensure that you allow unjailed cronjobs for this client and change the cron type to unjailed cron in the cronjob settings.
     
  9. sjau

    sjau Local Meanie Moderator

    actually I did now cancel the "jail" line. but my question was rather aimed at how to permanently disable the jailing of crons.

    (At the same time I'd also like to know how to enable the shell for the websites by default)
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    Thats what I explained you above in #8:

    .... and ensure that you allow unjailed cronjobs for this client and change the cron type to unjailed cron in the cronjob settings.

    PLease be aware that unjailed cronjobs can be a real security problem if you allow clients access to them. I explained you in #3 how to implement your cronjob in a secure way as html cronjon´b as a .sh file is not required when you use it just to call a few php files.
     
    Last edited: Apr 3, 2012

Share This Page