Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux cron job     - Git uses a small mind (Linux)

- Linux platform to prevent hackers to share practical skills (Linux)

- Linux system security configuration Collection (Linux)

- Ubuntu users to install the system indicator SysPeek 0.3 (Linux)

- Linux environment variable settings methods and differences (Linux)

- Redhat 7 modify the default run level method --RHEL7 use systemd to create a symbolic link to the default runlevel (Linux)

- Try debugfs restore the deleted files ext3 file system (Linux)

- Android using SVG vector graphics to create cool animation effects (Programming)

- How to properly set up a Linux swap partition (Linux)

- Android determine the device network connection status, and determine the connection (Programming)

- Zabbix system email alert Python script (Server)

- Use PXE with kickstart to install Linux automatically (Linux)

- Make command tutorial (Linux)

- imp / exp Oracle Database import and export commands (Database)

- Python calls the API interface in several ways (Programming)

- Four IDS intrusion detection tool under Linux environment (Linux)

- Use Python automatically cleared Android Engineering excess resources (Programming)

- MySQL performance view and configure finishing Daquan (Database)

- VMware6 achieve nat Internet (Linux)

- How to install Ubuntu California - the calendar application (Linux)

 
         
  Linux cron job
     
  Add Date : 2018-11-21      
         
       
         
  What Chapter 1 Crond that?

Crond linux system is used to periodically execute commands or specify procedures mandates a service or software. Under normal circumstances, after we installed CentOS5 / 6linux operating system, the default will start Crond task scheduling service. Crond service periodically (default is checked every minute) to check whether the system has the task of work to be performed. If so, it will execute the scheduled task work automatically according to the rules of their regular tasks set in advance. This Crond regular tasks and services that we use is equivalent to the alarm in the morning the same.

Chapter 2 Linux System crond cron job

linux system operation timing scheduling can be divided into the following two cases:

1, Task linux system itself regularly perform: Task system periodically carrying out its own, such as polling the system log, the backup system data, clearing the system cache, these tasks we need human intervention. E.g:

[Root @ web01 ~] # ll / var / log / messages *

-rw ------- 1 root root 585506 1 Yue 24 21:32 / var / log / messages

-rw ------- 1 root root 495226 12 Yue 13 14:41 / var / log / messages-20151213

-rw ------- 1 root root 501046 12 Yue 20 10:33 / var / log / messages-20151220

-rw ------- 1 root root 333767 12 Yue 30 20:27 / var / log / messages-20151230

-rw ------- 1 root root 332996 1 Yue 10 12:19 / var / log / messages-20160110

2, task work performed by the user: a user or system administrator work to be done on a regular basis, such as every five minutes, and a time server on the Internet time synchronization, 0:00 every night and site data backup site database data, these general work needs to be set by the user.

[Root @ web01 ~] # crontab -l

* / 5 * * * * / usr / sbin / ntpdate time.nist.gov> / dev / null 2> & 1

# * * * * * Echo "yangrz" >> / server / log / yangrz

Chapter 3 Command Description

crond service is running, and the user crontab is used to set the timing of the rule command.

crontab option

-l list (view the scheduled tasks set by the user)

-e to edit the configuration file regular tasks

crontab -e === vi / var / spool / cron / root

crontab -l === cat / var / spool / cron / root

Meaning Chapter 4 crontab syntax in period

# .---------------- Minute (0 - 59)

# | .------------- Hour (0 - 23)

# | | .---------- Day of month (1 - 31)

# | | | .------- 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

Chapter 5 crontab syntax Special symbols meaning

Some essentials section 6, the timing of writing tasks:

Tips 1: regular tasks necessary rules add comment

Tips 2: Timing Task command or program is best written script execution

Tips 3: Before executing shell script task plus / bin / sh

Tips 4: a command or script at the end of regular tasks plus> / dev / null 2> & 1

&> / Dev / null 1> / dev / null 2> / dev / null

Tips 5: the timing of implementation of the relevant tasks under the specified user

Tips 6: Production task program not free printout information

tar zcf echo 123> a.log

Tips 7: Script timed tasks performed to regulate the path (/ service / scripts)

Tips 8: Configuring the Scheduled task specification operation

About configuring process timed task specification Chapter 7

1) First, to the successful operation of the command line, and then copy the success of the command to the script, to reduce the chance of error in each small part.

2) Then the test script, the test is successful, copy the path of the script to the timing specification task configuration, do not knock the hand.

3) test in a test environment, and then deploy the official environmental norms.

Title: Every two hours the system / etc / service file packaged backup / tmp (preferably backed up into different packages each)

Burden: / etc / service does not exist, it should be / etc / services

Cd to the parent directory to the target content pack

Packaged frequency is divided, the package name must be accurate to the minute.

Ensure that the command executed correctly. Then wrote the script (copied into)

Timing Task command or program is best written script execution.

The correctness of test script (cron job how to write, how to test the command line)

Test the script correctly, Command line should copied.

* * * * * Tar zcvf / tmp / service - $ (date +% F-% H) tar.gz ./services

Written is wrong, the timing of the task configuration file had escaped, so it is a written document in order to avoid errors.

Title: Every night 0:00 to /tmp/services.tar.gz package before deleting the day before yesterday.

/ Var / log / cron *

This is the crontab log, run right or wrong, there will be inside the log output.

Chapter 8 Debugging regular work tasks methods:

1, increase the frequency of tasks debugging tasks (some tasks can not be used in a production environment is no opportunity to test)

2, Post Code: Personal development environment - the office environment -IDC test room test environment - "IDC formal environment (grouping, grayscale release)

3, adjust the system time debugging tasks (can not be directly used in the production environment), held for 5 minutes

4, script debugging log output timing of the task

5, pay attention to some of the problems caused by the task order

6, (* / 1 * * * * * echo "==" >> /tmp/oldboy.log> dev / null 2> & 1)

7, pay attention to the environment caused by variable timer task failure (java)

8, by crond cron job scheduled task debug log (/ var / log / cron)

9, put the script into the regular tasks inside, a lot of time to take a system variable, did not get, it will go wrong. At this time in the script system variable redefined again.

 

Chapter 9 crontab scheduled tasks production application problems Proverbs 10:

1. The system environment variable

2. Timing task to use absolute paths

3. Script permissions problem, add / bin / sh

4. Time variables problems with a backslash \% escapes, best script

5.> / dev / null 2> & 1 title (1> / dev / null 2> / dev / null, &> / dev / null)

6. Add a comment before a regular task rules

7. Use the script replace command line regular tasks

8. Avoid unnecessary procedures and command output

9. Packing target cut to the target directory on a

10. The timing of the task script commands try to use the full path (and the identification of relevant environmental variables).
     
         
       
         
  More:      
 
- Linux system security knowledge (Linux)
- SpringMVC garbage processing (Programming)
- ARP Linux-related operations (Linux)
- Use web2py + uWSGI + Nginx Web server built on Linux (Server)
- Windows environment Android Studio v1.0 Installation Guide (Linux)
- mysqldump MySQL command-line tool (Database)
- CentOS 6.4 installation and configuration LNMP build PHP server runtime environment (Server)
- CentOS 7.0 Automatic installation CD-ROM production Comments (Linux)
- Update GAMIT10.6 command (Linux)
- Linux software firewall ACL match point optimization (Linux)
- How Glances monitoring system on Ubuntu (Linux)
- Installation of network monitoring ntopng under CentOS 6.4 (Linux)
- Ceph distributed storage system is installed on a CentOS 7.1 (Server)
- Spring Boot + Nginx + Tomcat + SSL configuration notes (Server)
- DDOS Attacks and Prevention (Linux)
- Shell Programming Regular Expressions (Programming)
- DRBD + Heartbeat solve NFS single point of failure (Server)
- Get basic information about Linux server script (Server)
- Git uses a basic tutorial (Linux)
- Red Hat Linux mount U disk (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.