Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Linux cron job     - How to ensure the Linux SSH login security with one-time password (Linux)

- Use Ansible efficient delivery Docker container (Server)

- How to ensure that the Internet will not be attacked (Linux)

- Learning how to teach safety system to prevent your own IP leakage (Linux)

- Vagrant failed to start, stuck in Waiting for VM to boot solution (Linux)

- Valgrind * not * leak check tool (Linux)

- JavaScript object - Flexible and dangerous (Programming)

- Getting Started with Linux: Nginx Web Server How to Block Specific User Agents (UA) (Server)

- VSFTPD Security (Linux)

- Linux more efficient than select a model epoll (Linux)

- Classical sorting algorithm - Selection Sort (Linux)

- Oracle capability i / o (stress test database server i / o performance) (Database)

- How to use GRUB2 files directly from the hard disk to run ISO (Linux)

- Linux in order to make NMAP hide and seek with the firewall (Linux)

- Examples of Exploration Class File (Programming)

- Linux command to view the system status (Linux)

- Fedora 20 installation source Xen4.3.0 (Linux)

- GRUB2 boot Ubuntu Manual (Linux)

- Linux rpm command Detailed (Linux)

- curl Usage: Being the first site header and status codes (Server)

  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).
- How to use scientific data Docker quickly configure the development environment (Server)
- Oracle 10046 Event (Database)
- Using PHP MySQL library (Programming)
- VirtualBox 4.3 Can not open a new task for a virtual computer solution (Linux)
- 64 Ubuntu 15.04 Linux kernel upgrade to Linux 4.1.0 (Linux)
- Vim simple configuration (Linux)
- GAMIT learning materials finishing (Linux)
- Oracle View Object Information (Database)
- MySQL event table to achieve timing build a small note (Database)
- Four levels of intrusion on Linux server and counter-measures (Linux)
- How to run in support UDp Docker container JBoss data virtualization GA (Server)
- To use Android RecyclerView (Programming)
- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)
- Zabbix configure DataGuard monitoring (Database)
- Teach you how to protect the Linux operating system security tips (Linux)
- Python 2 Chinese garbage problem solved (Linux)
- Struts2 interceptor simulation (Programming)
- C language programming entry - Common operators (Programming)
- LAN in Ubuntu shared folders to Windows (Linux)
- MySQL innodb_table_stats table does not exist solution (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.