Welcome to Centmin Mod Community
Become a Member

Sysadmin how to run a cron job properly?

Discussion in 'System Administration' started by hitman, Feb 10, 2015.

  1. hitman

    hitman Member

    126
    11
    18
    Jul 18, 2014
    Ratings:
    +15
    Local Time:
    12:44 PM
    well i added in crontab 2 cronjobs
    Code:
    nano /etc/crontab
    
    the 2 cronjobs here
    and one of them is supposed to run every 15 minutes while the other once a day
    but if i check the /var/log/cron there is no log of them running

    am i doing something wrong?

     
  2. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Code:
    crontab -e
    is correct command to edit and initialise new crontabs
     
  3. hitman

    hitman Member

    126
    11
    18
    Jul 18, 2014
    Ratings:
    +15
    Local Time:
    12:44 PM
    ok i tried adding my cron as you said but it did not run
    when i run it through shh it runs fine,so i do not think i have some error in my syntax

    any other reason why it is not running?
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    check if cron service is running and start it if not and chkconfig on to ensure it starts on server reboots
    Code:
    service crond status
    service crond restart
    chkconfig crond on
    what is the exact cronjob line you added?
     
  5. sepulchre

    sepulchre Member

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    11:44 AM
    how can I delete running crons?
    What do I have to do in crontab -e (nano editor)?
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  7. chorong91

    chorong91 New Member

    16
    2
    3
    Dec 1, 2015
    Ratings:
    +2
    Local Time:
    7:44 PM
    I'm using laravel..
    I want to try scheduling so I already add this command to crontab -e:
    * * * * * php /home/path/to/artisan log:demo
    and I already make sure the command is working if I run it via cmd "php /home/path/to/artisan log:demo" then it display like this :
    (the command for write like below on laravel.log)
    [2016-08-03 13:59:34] local.INFO: Test 2016-08-03 13:59:34

    so I expect the cron is already working but its not working.
    nothing happend on my laravel.log
    but
    I see the /var/log/cron, and the output:
    Aug 3 14:01:01 digitalocean CROND[14484]: (root) CMD (php /home/path/to/artisan log:demo)
    Aug 3 14:02:01 digitalocean CROND[14499]: (root) CMD (php /home/path/to/artisan log:demo)

    I don't know what it means. I think its working? but why my command not work?

    NB:
    service crond status (return = "crond (pid 14907) is running...")
    service crond restart : (return =
    Stopping crond: [ OK ]
    Starting crond: [ OK ]
    )
    chkconfig crond on (return nothing)
     
    Last edited: Aug 4, 2016
  8. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    /var/log/cron only lists the command that is triggered not it's output
     
  9. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    Code:
    0 5 * * * root /opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1
    
    Hello this snapshot sh did nto work and I think the problem is in the log file creation

    please help
     
  10. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    did you create the directory /var/log/cron for first and then the file named /var/log/cron/snapshot.log as CentOS doesn't have a directory called /var/log/cron only a file called /var/log/cron by default
     
  11. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    very strange,

    after making the changes to reflect /var/log/snapshot.log , the wordpress was not working at all as if the site is down

    and was lucky that i have a backup

    however the crontab after restoring the google snapshot backup shows one line of @^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

    any help?
     
  12. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    the wordpress timout looks like it is related to
    csf -x

    command
     
  13. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    as explained at https://community.centminmod.com/threads/csf-firewall-and-google-cloud-firewall.11204/#post-47867

    when you run csf -x to disable CSF Firewall nothing is setup for iptables/firewall level on OS so you need to do all the whitelisting that CSF Firewall install by Centmin Mod automatically does yourself.

    If you use Google Cloud Firewall, you need to manually white list Centmin Mod used/required ports yourself. Centmin Mod can't configure Google Cloud Firewall, only CSF Firewall.
     
  14. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    yes, but I want to uninstall CSF, looks like it is not possible start wordpress if this unistalled
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    when you run csf -x to disable CSF Firewall nothing is setup for iptables/firewall level on OS so you need to do all the whitelisting that CSF Firewall install by Centmin Mod automatically does yourself at Google Cloud Firewall level
     
  16. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    I'm not as technical as you, but I think it is not related to the port whitelisting as I said I already enabled http and https
    I have another VPS instance that I uninstalled CSF and it works fine, I just don't know why this one dosn't,
     
  17. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    is the other working VPS on Google Cloud Compute server too ?
     
  18. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:44 AM
    yes, but when I checked, I discovered it is installed, I will investigate this later
     
  19. babyshark

    babyshark New Member

    20
    5
    3
    Jan 22, 2019
    Ratings:
    +7
    Local Time:
    4:44 PM

    Hi, did you fix this problem?

    I have same problem, run php /home/path/to/artisan cmd:excute is ok, but when add to cronjob, nothing run.

    service crond status
    service crond restart
    chkconfig crond on

    run all cmd before but new cronjob not work.

    cronjob -l is show full my cronjob
     
  20. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    tried instead of php use /usr/local/bin/php full path ?