Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to : executing a block of code every 24 hours in a server?

Tags:

linux

php

mysql

web

I want to fetch certain data from website every 24 hours. The code must be executed every 24 hours and update the MySQL database. How can I accomplish this without any user events?

Later i'll use same data to find the total difference.

totalIncrement = currentData - earlierData

While earlierData is fetched from the MySQl database and current data is fetched from the external website query.

I've heard of a cron on linux but have never tried it. Can any body just give a basic idea for that? or any reliable link?

May be i want to do it like this::

First create a PHP program/file that does the fetching job. Second execute that PHP file every 24 hours or so...

like image 473
mesur Avatar asked Aug 20 '11 06:08

mesur


1 Answers

Open a shell.
(Stop crond service service crond stop)
Use vi (or other editor) to edit cron file or type "crontab -e" to make your edit.
After edit hit "ESC". Then ":wq", to save and quit.
(Start the service again service crond start)
Stopping and starting the service is not needed if you use crontab -e.

Your script should be running by now. Check the syntax here or here. To view the changes you've made type "crontab -l".

I hope this helps.

like image 88
Panos Kal. Avatar answered Oct 05 '22 23:10

Panos Kal.