Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a cron expression to execute every 15 minutes

Tags:

session

cron

I am trying to setup a cron job to run the garbage collector every 15 minutes on my session directory to clean up sessions that are beyond the expiration limit I set in php.ini, in one of my subdirectory locations. I have never used cron jobs before so I was wondering if someone could help me.

What I have so far is:

15 * * * * /home/yadda/something/etc 
like image 426
Rujikin Avatar asked Dec 08 '12 22:12

Rujikin


People also ask

How do I schedule a script in crontab to run every 5 minutes?

tiny 4. /bin/ed Choose 1-4 [1]: Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes. Exit this file and save changes.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week . 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.


2 Answers

The following is an expression that will execute every 15 minutes:

0 0/15 * 1/1 * ? *

So your expression would be:

0 0/15 * 1/1 * ? * /home/yadda/something/etc

You may be interested in the cronmaker website.

like image 65
Ian R. O'Brien Avatar answered Nov 03 '22 01:11

Ian R. O'Brien


If you're using anacron (ubuntu default), then the notation is simply */15 as in

*/15 * * * * /home/yadda/something/etc

like image 22
Mr5o1 Avatar answered Nov 03 '22 00:11

Mr5o1