Adding cron tasks in Linux using SSH

in most hosting platforms we have the control panel console to add cron tabs. But in the case of our local linux machine, or server's which does not have control panel, we could use the following

adding the commands in the crontab

Login in the console as super user

Use the following command " sudo crontab -e " to open the crontab file.
Some times you will get a message to select the editor to open the file. select the desired editor. the crontab file will open and it contains the syntax for the crontab command. its looks like " # m h dom mon dow command "

m -> minute
h -> hour
dom -> date of month
mon -> Month
dow -> day of week

for setting cron for every minute use the following code

* * * * * yourcommand

for each five minutes

*/5 * * * * yourcommand

For hourly cron

0 * * * * yourcommand

For daily cron

0 0 * * * yourcommand

for yearly

0 0 1 1 * yourcommand

we could also run the cron in particular minute ,hour etc.

15,45 * * * yourcommand

the cron will run each 15 and 45 min of every hour

0 12,24 * * yourcommand

the cron will run each 12 and 24 every hour

where the value of * holds value "Every".

After setting the cronjob save the cron tab file.

For testing these cronsettings please follow following steps..

create the php script and save as mycron.php

$date = date("Y-m-d H:i:s");
mysql_query("INSERT INTO `test`(`timer`) VALUES ('$date')");

create corresponding database and table

`id` int(11) NOT NULL auto_increment,
`timer` datetime NOT NULL default '0000-00-00 00:00:00',

open crontab file add following command

*/5 * * * * php /pathto/mycron.php

and save the file and check back the mysql table for inserted values.

I hope this post will help you know details about adding cron job without the control panel or plesk console in your server or in the local machine


Running php script on command line & installing php5-cli library in phpserver

To run php in command line, you need to not only PHP, but also the PHP5-cli library in your php server. The PHP5-cli stands for command-line interpreter for the PHP5 scripting language. It is very useful when we need test our scripts from the shell. In some cases we need to install this library for running cronjobs on the server.

how to install php5-cli. in linux machines.

first login as super user : " su username "

after login just use the following command "sudo apt-get install php5-cli "

the php5-cli installation has completed

just restart your apache server. For that we can use the following command

How to restart a apache server on linux

sudo /etc/init.d/apache2 restart

After the restart of your server, the php5-cli has been installed on your server. and just try to run a simple php script on your server.


# function to get the byte format #
# @phpqa.blogspot.com #

function getByteFormat($number,$caption="small"){

$unit = "";

case($number >= 1099511627776):

$number = round($number / 1099511627776, 1);
$unit = $caption == "small" ? "TB" : "Terabyte";

case($number >= 1073741824):

$number = round($number / 1073741824, 1);
$unit = $caption == "small" ? "GB" : "Gigabyte";

case($number >= 1048576):

$number = round($number / 1048576, 1);
$unit = $caption == "small" ? "MB" : "Megabyte";

case($num >= 1024):

$number = round($number / 1024, 1);
$unit = $caption == "small" ? "KB" : "Kilobyte";

$unit = $caption == "small" ? "B" : "Byte";
$number = $number;


return number_format($number, 2).' '.$unit;


# How to use #

echo getByteFormat(10995116277,"big");
echo getByteFormat(109951162799,"small");
echo getByteFormat(10995116261099);


please try this function and lemme give your feedback as comments