Centos cron jobs
- Let's create a directory this purpose.
# cd
[root@server ~]# mkdir crontests
[root@server ~]# cd crontests
- Sample script for testing
[root@server crontests]# vim job.sh
#!/bin/bash
today=$(date)
touch /root/crontests/"$today"
- Make script executable*
[root@server crontests]# chmod +x job.sh
- 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
- 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
- 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:
Laravel scheduler cron jobs