Get the most out of your Centmin Mod LEMP stack
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

    110
    9
    18
    Jul 18, 2014
    Ratings:
    +13
    Local Time:
    4:42 AM
    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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    Code:
    crontab -e
    is correct command to edit and initialise new crontabs
     
    • Like Like x 1
  3. hitman

    hitman Member

    110
    9
    18
    Jul 18, 2014
    Ratings:
    +13
    Local Time:
    4:42 AM
    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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    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?
     
    • Like Like x 1
  5. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    3:42 AM
    how can I delete running crons?
    What do I have to do in crontab -e (nano editor)?
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  7. chorong91

    chorong91 New Member

    16
    2
    3
    Dec 1, 2015
    Ratings:
    +2
    Local Time:
    11:42 AM
    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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    /var/log/cron only lists the command that is triggered not it's output
     
  9. ahmed

    ahmed Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 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 Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 AM
    the wordpress timout looks like it is related to
    csf -x

    command
     
  13. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 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

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:42 AM
    Nginx 1.13.x
    MariaDB 5.5
    is the other working VPS on Google Cloud Compute server too ?
     
  18. ahmed

    ahmed Member

    201
    15
    18
    Feb 21, 2017
    Ratings:
    +21
    Local Time:
    3:42 AM
    yes, but when I checked, I discovered it is installed, I will investigate this later