Boot up
Start-up should be our very frequent needs, we often need to automatically execute certain commands at boot to open the service, process, etc., with it we do not have to enter the same heap every time the command. Chkconfig command
Use the Chkconfig command to start a specific service or program at a different startup level.
Let's start with the Linux operating level:
Level 0 means: shutdown
Level 1 means: Single user mode
Level 2: Multi-user command line mode with no network connection
Level 3 means: Multi-user command line mode with network connection
Level 4 means: not available
Level 5 means: Multi-user mode with graphical interface
Level 6 means: reboot
The Chkconfig command is as follows:
Chkconfig--list//command to view the open self-launch list that has been set.
Xxxd 0:off 1:off 2:on ... The result of 6:off//list is that the Xxxd service starts automatically at the start level of 2 3 4 5.
Chkconfig--add xxxd//Add a XXXD service to the task list
Chkconfig [--level 1/2/. /6] Xxxd on/off//set xxxd with service in N state is on/off, [] omitted in level 2,345 do not open
Chkconfig--del xxxd//delete rc.d file edit from XXXD service in task List
You can also directly edit the files in the/etc/rc.d/directory to enable startup. There are many files in this directory, RCN.D is the Startup folder in the case of the boot status N, rc, Rc.sysinit, INIT.D are the system's module or the system settings of the self-starter file [clamp].
We use vim rc.local to edit the rc.local file to customize our own self-starter program. The command is very simple, just as usual in operation. Such as/usr/local/apache/bin/apachectl start indicates that the Apache server is booting from. At implementation timed tasks
At is a simple function simple task program, it can only be a one-time scheduled tasks, the use of the following:
#at time//at and start at command
At>operation//Enter the action to be performed
At>ctrl+d//press Ctrl+d to exit command edit
The common form of time is as follows
At h:m tomorrow//Next day H point M min
At now + N minutes/hours/days/weeks//in n min/time/day/banishment
At midnight//Midnight =-=
At h:m pm/am//In the morning/afternoon of H point m minutes
We can also view the current command for at in the/var/spool/at file. It is also important to note that the Linux default ATD process is turned off and needs to be opened manually. Crontab implementation of timed tasks
Linux built-in cron process can help us to achieve these requirements, cron with shell script, very complex instructions are no problem. Cron Introduction
The cron daemon is a small subsystem of utilities and configuration files that can find a style of cron on almost all UNIX-like systems, and we can use PS Aux|grep cron to find the Crond daemon.
We often use the crontab command is the shorthand for cron table, it is a cron configuration file, or it can be called a job list, we can find the relevant configuration file in the following folder.
The/var/spool/cron/directory contains crontab tasks for each user, including root, and each task is named after the creator's name
/etc/crontab This file is responsible for scheduling various management and maintenance tasks.
/etc/cron.d/This directory is used to store any crontab files or scripts to be executed.
We can also put the script in the/etc/con.hourly,/etc/con.daily,/etc/con.weekly,/etc/con.monthly directory, and let it execute once per hour/day/week, month. Use of crontab
The commands we use are as follows:
1
2
3
4
crontab[-u username] //省略用户表表示操作当前用户的crontab
-e (编辑工作表)
-l (列出工作表里的命令)
-r (删除工作作)
We use CRONTAB-E to enter the current user's worksheet editing, is a common vim interface. Each line is a command.
Crontab commands are made up of time + action, with time points, hours, days, months, and Friday types, with operators
* All numbers within the value range
/number of numbers per past
-From X to Z
, hash number
Here are a few examples.
Time Comment
1
2
3
4
0 0 25 12 * //在12月25日的0时0分
*/5* * * * //每过5分钟
* 4-6 * * * //每天的4 5 6点
* * * * 2,5 //每周二和周五
With a simple shell script
If our command has a very complex operation such as logical judgment, then it is a bit difficult to edit the crontab directly, and then we can use the shell script. Its origin, classification definition and the problem is not, no longer say, we directly say its usage.
We use vim/usr/sh/test.sh to edit a shell script using vim
1
2
3
#!/bin/sh //声明开始shell脚本
a = "hello world"//定义一个shell变量
echo$a //熟悉的echo,输出a变量
Then crontab-e edit crontab, add */5 * * * */usr/sh/test.sh run test.sh script every five minutes or/phppath/php/filepath/test.php To use PHP processes to execute PHP programs.
Turn from:
Linux Systems perform tasks automatically (GO)