Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux cron job     - RHEL6.5 replace local YUM source (Linux)

- Plasma 5.4 How to install on Kubuntu 15.04 (Linux)

- CentOS 7 Docker build private warehouse registry (Linux)

- MongoDB start under Linux (Database)

- MySQL root password reset under CentOS (Database)

- Binary search and modification (Programming)

- Android timer use (Programming)

- The difference between free command displays the buffers and cache (Linux)

- Ubuntu ADSL dial-up Internet access (Linux)

- Linux initialization init systems - Systemd (Linux)

- Oracle bdump file soaring (Database)

- Linux install Maven and SVN client (Linux)

- Ubuntu Linux use ufw or iptables firewall configuration (Linux)

- Use Linux firewall camouflage defense hacked (Linux)

- Ubuntu way of decompressing files (Linux)

- Understanding and Memcached MongoDB arbitration node, Zookeeper, Redis Recovery Programme Thoughts (Database)

- Python configuration tortuous road of third-party libraries Numpy and matplotlib (Programming)

- Debian 7.6 install Nvidia graphics driver (Linux)

- MongoDB slice simple example (Database)

- ORA-04031 error appears in the solution 11.2.0.4 run utlrp.sql (Database)

 
         
  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:      
 
- CentOS yum install LAMP (Server)
- To build PHP environment (Nginx + MariaDB + PHP7) under CentOS 6.5 (Server)
- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)
- TCP network communication Java Programming (Programming)
- Redmine Installation (Linux)
- To_teach you three strategies to prevent the LAN IP address theft (Linux)
- Use OpenSSL for RSA encryption and decryption (Linux)
- Oracle procedure or function Empty Table (Database)
- Linux iptables firewall settings to use (Linux)
- Linux System Getting Started Learning: compile and install ixgbe driver in Ubuntu or Debian (Linux)
- Lenovo Ultrabooks Ubuntu system can not open the wireless hardware switch solutions (Linux)
- Linux System Getting Started Learning: Linux command in w (Linux)
- CentOS 6.6 command-line automatic completion (Linux)
- Install DB2 V10 and Data Studio V3 under Linux (Ubuntu) environment (Database)
- Ubuntu Server security risk checks (Linux)
- Fedora 21 setting boot script (Linux)
- How to install the client sqlplus under linux (Database)
- Linux automatic installation and implementation (Linux)
- Ubuntu file security removal tool (Linux)
- Docker knowledge base (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.