Skip to content

Instantly share code, notes, and snippets.

@mtvbrianking
Created July 8, 2019 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtvbrianking/507626a7e619aa26eb2c07cb043674d1 to your computer and use it in GitHub Desktop.
Save mtvbrianking/507626a7e619aa26eb2c07cb043674d1 to your computer and use it in GitHub Desktop.
Setup cron jobs on centos

Centos cron jobs

  1. Let's create a directory this purpose.

# cd

[root@server ~]# mkdir crontests

[root@server ~]# cd crontests

  1. Sample script for testing

[root@server crontests]# vim job.sh

#!/bin/bash

today=$(date)

touch /root/crontests/"$today"
  1. Make script executable*

[root@server crontests]# chmod +x job.sh

  1. Test bash script

[root@server crontests]# ./job.sh

[root@server crontests]# ll
total 4
-rwxr-xr-x 1 root root 60 Jul  8 10:28 job.sh
-rw-r--r-- 1 root root  0 Jul  8 10:58 Mon Jul  8 10:58:01 EAT 2019

You should have a file created with the current timestamp

  1. Register new job

[root@server crontests]# crontab -e

Add the following snippet to the file. You can determine the run intervals using crontab.guru

# Run this job every minute
* * * * * /root/crontests/job.sh
  • Verify job is registered
[root@server crontests]# crontab -l

# Testing centos cron jobs
* * * * * /root/crontests/job.sh
  1. Validate job is running
[root@server crontests]# ll
total 4
-rwxr-xr-x 1 root root 60 Jul  8 10:28 job.sh
-rw-r--r-- 1 root root  0 Jul  8 10:58 Mon Jul  8 10:58:01 EAT 2019
-rw-r--r-- 1 root root  0 Jul  8 10:59 Mon Jul  8 10:59:01 EAT 2019
-rw-r--r-- 1 root root  0 Jul  8 11:00 Mon Jul  8 11:00:01 EAT 2019
-rw-r--r-- 1 root root  0 Jul  8 11:01 Mon Jul  8 11:01:01 EAT 2019
-rw-r--r-- 1 root root  0 Jul  8 11:02 Mon Jul  8 11:02:01 EAT 2019

You should have a file created every minute with the current timestamp

Source:

@mtvbrianking
Copy link
Author

Laravel scheduler cron jobs

; Run Laravel scheduler every minute.
* * * * * php /var/www/html/example.com/artisan schedule:run >> /dev/null 2>&1

@mtvbrianking
Copy link
Author

Issues:

Dispatcher w/ Laravel duplicating output

https://stackoverflow.com/a/26682246/2732184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment