Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Timing task Crontab under Linux system     - Linux System Getting Started Learning: the local time in between Perl and UNIX timestamp conversion (Linux)

- DRBD-based installation and configuration of CentOS 6.5 (Server)

- After reloading the cinder-volume OpenStack not start properly (Server)

- Install the system cleaning software under Linux: BleachBit 1.4 (Linux)

- GCC and gfortran write MEX program (Matlab2012a) under Ubuntu 14.04 (Programming)

- Binary Tree Traversal (Linux)

- Git build a team development environment operating drills (Linux)

- About Java 7 module system (Programming)

- Linux Systemd-- To start / stop / restart services in RHEL / CentOS 7 (Linux)

- Steps to build MPICH2 development environment on CentOS 6.4 (Linux)

- Ubuntu configuration SVN and http mode access (Server)

- Linux see whether there is a hacker program (Linux)

- Cygwin install Python MySQLdb (Linux)

- AngularJS asynchronous service testing and Mocking (Programming)

- C ++ handling text input (Programming)

- CentOS 7.0 running Docker kernel error solution (Server)

- Linux non-root user uses less than 1024 ports (Linux)

- RHEL5.x RHEL6.x replace CentOS yum source (Linux)

- Linux kernel to achieve soft RPS network to receive soft interrupt load balancing to distribute (Linux)

- Use PDFBox processing PDF documents (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

3.Demo
(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
    exit
else
  date = $ (date + "% Y-% m-% d% H:% M:% S")
  /etc/init.d/mysqld restart
  echo 'mysqld exception at' $ date 'and restart'
fi

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
  exit
else
  date = $ (date + "% Y-% m-% d% H:% M:% S")
  /etc/init.d/httpd restart
  echo 'apache exception at' $ date 'and restart'
fi

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
then
      echo 'server is running'
else
      if ping -c 1 localhost> / dev / null 2> & 1
      then
        echo 'server exception but ip ping success'
      fi
fi

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.
     
         
         
         
  More:      
 
- Installation through the network Debian 7 (Wheezy) (Linux)
- Debian 7.6 install Nvidia graphics driver (Linux)
- Yii PHP Framework Getting Started tutorial (Linux)
- To delete the directory and all specified files under the Mac (Linux)
- The Samba service does not have permission to access (Server)
- Nginx introduced Dynamic Module Architecture (Server)
- The Definitive Guide to Linux NAT network connection (Linux)
- Linux device driver development small example --LED lights (Programming)
- Ubuntu 14.04 Nvidia proprietary drivers for install two graphic cards (Linux)
- libreadline.so.6: can not open shared object file problem solution (Linux)
- Linux - Common process the command (Linux)
- Install DB2 V10 and Data Studio V3 under Linux (Ubuntu) environment (Database)
- Implement firewall function on a closed Linux machine (Linux)
- Zend Studio PHP syntax color scheme to export (Linux)
- Dockerfile use to build a mirror-based CentOS 7 (Linux)
- Linux system started to learn: Teaches you install Ubuntu 15.04 on VirtualBox (Linux)
- Oracle 11g manually create a database (Database)
- Computer black magic: tail recursion (Programming)
- Keepalived achieve high availability Nginx Reverse Proxy (Server)
- Ubuntu 12.04 install RTL8723BE wireless network card driver (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.