Creating a cronjob that runs every after one minute

Posted on: November 25, 2008

What is crontab? crontab  is  a  program which is used to install, deinstall or list the tables used to drive the cron(8) daemon in Vixie Cron. You can easily  have your    own    crontab,    and    though    these    are    files   in /var/spool/cron/crontabs, they are not intended to be edited  directly.
If  the /etc/cron.allow file exists, then you must be listed therein in order to be allowed to use this command.  If the  /etc/cron.allow  file does  not  exist  but the /etc/cron.deny file does exist, then you must not be listed in the /etc/cron.deny file in order to use this  command. If neither of these files exists, then depending on site-dependent configuration parameters, only the super user will be allowed to use  this command,  or  all  users will be able to use this command. For standard Ubuntu or Debian systems, all users may use this command.
The options of crontab command are given below:
If the -u option is given, it specifies the  name  of  the  user  whose crontab  is  to be tweaked.  If this option is not given, crontab examines “your” crontab, i.e., the crontab of the person executing the command.
crontab -l will show you your currently set up cron jobs on the server.
crontab -r will delete your current cron jobs.
crontab -e will allow you to add or edit your current cron jobs by using your default text editor to edit your “crontab file”. In my case Nano
Note that, vi has a bug in it and won’t work to edit your crontab! We recommend nano (which is just like pico), which is the default editor anyway!

Your crontab includes all the cron jobs you’d like, with one cron entry per line. A cron entry looks like this:
*/2 * * * *     /home/user/ #This will run in every other minutes.
The first number is the minute of the hour for the command to run on.
The second number is the hour of the day for the command to run on.
The third number is the day of the month for the command to run on.
The fourth number is the month of the year for the command to run on.
The fifth number is the day of the week for the command to run on.

You may divide any number by a number to meet your requirements like this */2 * * * *

Now let’s create a new cronjob for a PHP file which will simply echo the running date and time of cronjob. Let’s say the cron will run every after one minute.

Step-1: Create a file named my_cron.php at /var/www/my_cron.php with the following code:
echo ‘This cronjob run at: <b>’.date(‘d-F-Y, h:sa’,time()).'</b>’;

Step-2: Open terminal and type the following command:
crontab -e

Step-3: Now NANO editor should be opened. Write the following text and save it by pressing the F3 key and hitting ENTER. Alternatively you may some keyboard combinations to meet the goal as per the instructions given at the bottom of NANO. The following command will be executed in every minutes.
* * * * * PHP /usr/bin/php -q /var/www/mycron.php

Step-4: Win!!

Now you may see the list of existing cronjob by executing the command crontab -l. If your cronjob is successfully done, then you should get a report every after one minute from the system. Check your mail!!

Tags: , ,

11 Responses to "Creating a cronjob that runs every after one minute"

First Question should be What is CronJob?

it should be */30, not */2

@Hasin bro,
I made a cron yesterday with */2 * * * * with SSH client which is running every other minutes just fine:p AFAIK the command should be for:

Every minutes = * * * * *
Every other minutes = */2 * * * *
Every after 10 minutes = */10 * * * *
Every after 15 minutes = */15 * * * *
Every after 30 minutes = */30 * * * *

Would you please check it?

cool – it was conceptual – sorry for my prev comment 😀

Ferdous bro this is an important post but i dont have any idea about cronjob:-/

Similar theme read on what that already a blog, but here certainly it is described more interestingly. Thanks the author of a blog.
Скачать мультфильмы быстро

Я тоже долгое время увлекался этой темой, и полностью согласен с мыслями автора. Респект.

Спасибо за статью, всегда рад почитать вас!

Найс темка ))

Теперь буду пoчаще читать, мне так пoнравилoсь 😀

раз 5 пытался сегoдня утрoм зайти на блoг – не пускалo. Видать, у твoегo хoстера были прoблемы..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

I am Nurul Ferdous a Zend Certified Engineer (ZCE), serving at Bangladesh Internet Press Limited (BIPL) as programmer. I am a FOSS advocate and love RnD.


Me @ LinkedIn

View Nurul Ferdous's profile on LinkedIn

My Photos @ Flickr

Blog Stats

  • 42,882 [ Vistors ]

My Twitter Updates

%d bloggers like this: