Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Timing task Crontab under Linux system     - Design and implementation of environment sniffer running under Linux (Linux)

- Gitolite how to import other Git repositories (Server)

- MySQL stored procedures execute dynamic sql statement (Database)

- Spark read more HBase tables a RDD (Server)

- The bulk batch multiple rows of data collect (Database)

- The difference Docker save and export commands (Linux)

- Ubuntu to install systems Indicator Sticky Notes 0.4.4 (Linux)

- CentOS 7 update source - the use of domestic sources 163 yum (Linux)

- SSH service configuration to use a certificate login Linux server (Server)

- Comparison of sorting algorithms (Programming)

- Firewall settings oracle remote connection in Linux systems (Linux)

- Linux installation Jetty deployment under RedHat5 8 (Linux)

- CentOS install Redis (Database)

- Docker + OpenvSwitch build experimental environment VxLAN (Server)

- SSH does not require a password to log on to a Linux server (Server)

- Cacti Linux-based system monitoring and alarm (Linux)

- MySQL root password reset under CentOS (Database)

- Linux partition command (Linux)

- MySQL configuration file my.cnf increase the log file parameter error (Database)

- Security: Unix operating system intrusion tracking Strikes Back (Linux)

  Timing task Crontab under Linux system
  Add Date : 2017-08-31      
  What is the Crontab

Crontab is a regular task tool under Linux system, the equivalent of WIN7 system mission plan, allowing the system time to make a detailed Cron

What can be done Crontab

Crontab can be used to add a Linux or Unix system scheduled tasks, so that the system timing to execute a command, such as the database server needs to restart the next day in the morning, every morning it is impossible to manually restart. You can use Crontab Timing task add 5:00 to restart the database, the system every day to 5:00 will automatically restart the data.

Crontab still many things to do, such as sending e-mail regularly, regular inspection and inventory, clean up the log regularly, regular backup of the database, in short, as long as it has the basic task performed periodically Crontab can be used to achieve, of course, provided in the Linux system environment.

Crontab simple to use

1. Common basic commands
crontab -l lists all the scheduled tasks currently logged in user
crontab -l -u XXX XXX user lists all the scheduled tasks, if there is no will prompt no crontab for XXX
crontab -e to edit the user's current scheduled tasks
crontab -r Remove the current user's regular tasks
2. The timing of the task set time
* * * * * Per minute
* / 1 * * * * per minute
05 * * * at five o'clock every execution
0-59 / 2 * * * * every two minutes to perform, and are even a few minutes to perform, such as 2,4,6
1-58 / 2 * * * * every two minutes to perform, and the odd few minutes to perform, such as 3,5,7
00 No. 1, 5, 10 * * per month, on the 5th, 10th execution
001-5 * * 1-5 month implementation of Hao

(1) execute the command: crontab -e

(2) Input * * * * * date >> /tmp/date.log

(3) After saving, the system will prompt crontab: installing new crontab

(4) Run: tail -f /tmp/date.log system will be able to see every minute of time to print out this document date.log

Crontab + Shell with real-time monitoring system

In the operation process of the system site, we need to know whether the site or system 24 hours in normal operation, the normal operation of the system generally requires the support of two things, one is the web server, a database.
Then we need real-time monitoring web server and database is running. Let's analyze how needs to apache and mysql database server as an example.
1. Monitoring mysql database running normally
Normally after we log on a Linux server, you want to view the current Mysql server is running, we'll execute pgrep mysql view, if you have to print out the process ID Description mysql is in normal operation.
According to this principle can be written as follows SHELL script:

#! / Bin / bash
check = `pgrep mysql`
if [-n "$ check"]; then
  date = $ (date + "% Y-% m-% d% H:% M:% S")
  /etc/init.d/mysqld restart
  echo 'mysqld exception at' $ date 'and restart'

To determine whether there mysql process, the presence of the normal does not exist then the mysql may hang up, you can perform the restart operation, of course, you can also send a message directly to the specified mailbox.

2. Monitoring apache is functioning properly monitor mysql based on experience, we can write a script SHELL:

#! / Bin / bash
check = `pgrep httpd`
if [-n "$ check"]; then
  date = $ (date + "% Y-% m-% d% H:% M:% S")
  /etc/init.d/httpd restart
  echo 'apache exception at' $ date 'and restart'

There may be a kind of apache may not be on the same server, you can use the following SHELL scripts:

if curl -m 10 -G localhost: 81> / dev / null 2> & 1
      echo 'server is running'
      if ping -c 1 localhost> / dev / null 2> & 1
        echo 'server exception but ip ping success'

The principle is similar to directly access URL to determine whether there is a response, respectively judgment apache port and server IP. If the system is not responding to access apache service may be hung up, there is a server may be hung up, so use PING way to determine if the server is normal.

The last step is to add the script to the timing of these two tasks to perform:

crontab -e

* * * * * Sh /alidata/test/mysqlListener.sh >> /var/log/mysqlL.log

* * * * * Sh /alidata/test/httpdListener.sh >> /var/log/httpdL.log

So every minute to judge whether apache and mysql running, basically reached the real-time monitoring, if coupled with e-mail notification, as long as the system fails to achieve real-time e-mail notification.
- Java in the final qualifier (Programming)
- Machine Learning: Classification of the curse of dimensionality (Programming)
- CentOS yum install LAMP (Server)
- Linux, Google Test (GTest) test environment to build step (Linux)
- CentOS 6.4 of cron scheduled task configuration (Linux)
- Learn about EditText little depth (Programming)
- JavaScript Advanced Programming notes event capture and event bubbling (Programming)
- When Linux Detailed time zone and common function of time (Linux)
- Batch kill processes using awk command (Linux)
- CentOS7 method to upgrade the kernel to 3.18 (Linux)
- Installation Enpass secure password manager on Ubuntu (Linux)
- Use OpenSSL to generate a certificate (Linux)
- Struts2 Result Types (Programming)
- OpenStack image production in the CentOS 6.2 (Linux)
- Repair after installing Ubuntu no boot device error (Linux)
- C # compiler to achieve functional use in the runtime (Programming)
- Linux System Getting Started Learning: complete installation on Debian or Ubuntu kernel source (Linux)
- [JavaScript] catch (ex) statements of ex (Programming)
- Binary tree and some basic operations with binary list (Programming)
- Configuring Sublime Text Python runtime environment 2 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.