Write a summary of some scripts----create a sub-table

Source: Internet
Author: User

Some time ago have been writing some running data script, today just have time to summarize.

In general, it is divided into 2 types, one for tasks written in a single file, and a direct include such as database drivers. When you are running:
Cd/path/to/project
/usr/local/php5.x/php task.php
The other is nested within the framework of a Contorller file inside, the invocation method can refer to the way CI. Like what:
Cd/path/to/project
/usr/local/php5.x/php index.php tempscript methodName param1 param2

The script tasks I've written are probably divided into the following categories:
1. Daily creation of sub-tables (so-called sub-table sub-Library)
2. Historical data migrated to the sub-table. (previously single table dozens of G table, need to do optimization sub-table)
3. Synchronize the data to other tables.
4. Migrating data from one db to another db. (e.g. from Mssql->mysql, or vice versa)
5. Sync from database to Redis.
6. Change the cache file to read.

Say first: Create a daily table.
To be able to receive the start time parameter, and generate the number of days at once.
At the time of creation, first judge the Create TABLE IF not EXISTS (assuming we are using MySQL)
Use the For loop to traverse the Generate talent table, failing or successfully giving the prompt output. The default is best to generate 2 days at a time. There is time to cross, even if today's generation of tomorrow's sub-table fails, the next day execution will be repeated judgment and creation.
Write a shell to complete the daily scheduled tasks as follows:

#!/bin/bash

cd/usr/local/nginx/html/project_path/
/usr/local/php-5.4.25/bin/php index.php Backstage Task createlogtablebydate

#curl "Http://192.168.1.234:5555/backstage/task/createLogTableByDate"

Because the project has more than one task to execute, so do not go to use CRONTAB-E to set up, directly in the/etc/crontab write the following:
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/

# for details see Mans 4 Crontabs

# Example of Job definition:
#.----------------Minute (0-59)
# |.-------------Hour (0-23)
# | |.----------DAY of Month (1-3O)
# | | |.-------month (1-12) OR jan,feb,mar,apr ...
# | | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * * user-name command to be executed

#每隔5分钟执行一次脚本
#*/5 * * * * root/root/shell/sycsomethingtoredis.sh
#*/5 * * * * root/root/shell/syncusers.sh

#某平台
*/1 * * * * root/root/shell/someprojectclient.sh
*/1 * * * * root/root/shell/someprojectscript.sh
XX * * * * root/root/shell/someprojectscriptcreatetable.sh

#每隔2两小时执行一次脚本
#0 */2 * * * root/root/shell/statisdata.sh

#每天23点执行一次脚本
#* * * * root/root/shell/createaddetailtable.sh
#20 * * * root/root/shell/sinak.sh

#每天00:10 execute a script to create a log table
* * * * * root/root/shell/createsomelogstable.sh

XX * * * root/root/shell/statis.sh

Write a summary of some scripts----create a sub-table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.