Crontab combines the shell written by PHP to complete the program that automatically update data

xiaoxiao2021-03-06  46

Crontab combines the shell written by PHP to complete the program that automatically update data

You can see: http://www.cnblogs.com/candle806/archive/2011/12/15/2288491.html

Author: Heart lamp 1. Write shell written in PHP

Getscore.php

#! / usr / local / bin / php -q

$ g_dbhost = "localhost";

$ G_DBNAME = "16328";

$ G_DBUSERID = "root";

$ g_dbpasswd = ""

Function Opendb () {

Global $ g_dbhost, $ g_dbuserid, $ g_dbpasswd, $ g_dbname, $ g_errmsg;

$ conn = mysql_connect ($ G_DBHOST, $ G_DBUSERID, $ G_DBPASSWD);

IF ($ conn) DIE ($ g_errmsg.mysql_error ());

@MYSQL_SELECT_DB ($ G_DBNAME, $ conn);

IF (mysql_errno ()) DIE ($ g_errmsg.mysql_error ());

RETURN $ conn;

}

OpenDB ();

$ DATE = DATE ("Y-M-D");

$ TIME = DATE ("H: I: S");

Echo $ SQL = "Insert Into Football_rate Set Fr_Date = '$ DATE', FR_TIME = '$ TIME'"

$ RES = mysql_query ($ SQL) or Die (MySQL_ERROR ());

?>

database:

Create Table `16328` (

`fr_date` Date Not Null Default '0000-00-00',

`fr_time` VARCHAR (32) Not null default ''

ENGINE = myisam default charSet = latin1;

2. Set crontab

Execute a vi / etc / crontab command

Shell = / bin / bash

PATH = / sbin: / bin: / usr / sbin: / usr / bin

Mailto = root

# Here preset is root, and the crone will send the result to this account, we can take it, but you need to build this account in advance.

HOME = /

# Run-parts * * * * * root /Home/bjbs270/public_html/getscore.php # Performed a specified program 01 * * * * root run-parts per minute 01 * * * * root run-parts /etc/cron.Hourly02 4 * * * root Run-parts /etc/cron.daily22 4 * * 0 root run-parts /etc/cron.weekly42 4 1 * * root run-parts /etc/cron.monthly3. Restart crones / etc / rc.d / init.d / Crond Start / Stop / Restart attached:

CRONTAB is a timing task trigger under UNIX system, and its user's permissions are recorded in the following two files: /usr/var/adm/cron.deny: The user listed in this file does not allow the crontab command; /usr/var/adm/cron/cron.allow: The user listed in this file allows the crontab command; the format of the crontab command is: crontab -l | -v | -r | -e [username], its parameter meanings As Table 1: Parameter Name Meaning -L Displays the content of the user's crontab file -V display the content of the user's crontab file and its submission, only for the Compaq series -R from the crontab file to remove the user's crontab file-E edit User crontab file

The CRONTAB file established by the user is stored in / var / spool / cron / crontabs, and its file name is consistent with the username.

Its format is divided into six sections, the first five sections are time setting segments, and the sixth paragraph is the command segment to be executed.

The format is as follows: * * * *

The meaning of its time period is as follows:

Segment Meaning The first paragraph represents the second paragraph of the second paragraph representing the hour 0-23 representative date 1-31 The fourth paragraph 1-12 paragraph 5 represents the week, 0 represents Sunday 0-6

Example: If the content of the user's crontab file is: 29 19 * * * Echo ITS DINNER TIME, the system is displayed daily 19:29 on the 'ITS DINNER TIME'.

CRONTAB can use SLEEP to implement the effect of secondary timing tasks. For example, if you want to perform a script every 20 seconds, you can write:

* / 1 * * * * / path / to / my / script

* / 1 * * * SLEEP 20 && / path / to / my / script

* / 1 * * * SLEEP 40 && / PATH / TO / MY / SCRIPT

Attachment: When this six paragraphs don't have, the program is executed in 1 second. I use the cron when using cron, it is used as a command to execute a command one in each second. This idea misleaded me a long time, in fact, this sentence means that every hour's first minute program is executed once. What is the difference between the modification / etc / crontab and crontab -e instructions?

/ etc / crontab setting is for the entire system, only root has permissions to modify crontab -e settings for individuals, using crontab-E-constructed personal scheduling in / var / spool / cron /

crontab-E // Edit Schedule crontab -r // Remove Crontab -L // List Schedule

转载请注明原文地址:https://www.9cbs.com/read-80050.html

New Post(0)