Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux cron job     - Use Redis as time-series database: why and how (Database)

- How to configure security services under Linux (Linux)

- Use the vi text editor and copy and paste Linux tips (Linux)

- Three methods easy data encryption on Linux (Linux)

- Solve the compatibility problem between Linux and Java at the source in bold font (Linux)

- CentOS6 5 source compiler installation Hadoop2.5.1 (Server)

- Linux server alarms using Java (Server)

- Debian 8 Jessie install LAMP server tutorial (Server)

- Xtrabackup creates a slave node without downtime (Database)

- Oracle archive log deletion (Database)

- ASP.NET 5 (vNext) Linux deployment (Server)

- Hadoop scheduling availability of workflow platform - Oozie (Server)

- To delete the directory and all specified files under the Mac (Linux)

- HDFS Hadoop Distributed File System Works (Server)

- Installation and use Docker under Ubuntu 14.04 (Linux)

- Use this one-time password via SSH secure login Linux (Programming)

- Ubuntu and derived versions of the user how to install G Mic 1.5.8.5 (Linux)

- Port Telnet command to detect the remote host is turned on (Linux)

- How to configure Ceph stored on CentOS 7.0 (Server)

- Linux host dual LAN transceiver package ARP problem (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:      
 
- Java rewrite the hashcode method (Programming)
- GEC2440 easiest a kernel compile Linux2.6.30.4 (Programming)
- Keepalived + HAProxy high availability load balancing (Server)
- Nginx Beginner Guide (Server)
- SELinux multi-level security (Linux)
- apt-get and apt-cache show command examples (Linux)
- MariaDB phpMyAdmin installation and configuration issues to resolve under CentOS7 (Database)
- Analyzing Linux server architecture is 32-bit / 64-bit (Server)
- Oracle RMAN-06023 and ORA-19693 errors (Database)
- Ubuntu system process is bound CPU core (Linux)
- Linux system security norms (Linux)
- SQL Beginner Guide (Database)
- CentOS 7.0 Experience with previous versions (Linux)
- Ubuntu and Archlinux install Notepadqq 0.50.2 (Linux)
- MySQL root password reset under CentOS (Database)
- OpenStack package problems and solutions under CentOS6 (Linux)
- C language - Traverse pci device (Programming)
- Ubuntu 14.04 Install WordPress on Nginx (Server)
- Linux `dirname $ 0` (Linux)
- Compile and install Redis and register as a system service under RedHat5.8 environment (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.