Required Linux Command-crontab

Source: Internet
Author: User

The following describes the 60 required Linux commands that must be mastered by new users. If you have mastered these commands, your technology will be greatly improved, we hope that the technology will be greatly improved after reading this article.

Crontab
1. Role
You can use the crontab command to modify the crontab configuration file. Then, the configuration is executed by the cron utility at an appropriate time. This command has the permission of all users.
2. Format
Crontab [-u user] File
Crontab [-u user] {-l |-r |-e}
3. Main Parameters
-E: run the text editor to set the time table. The text editor is vi.
-R: Delete the current time table.
-L: list the current time table.
Crontab
The file format is m h d m d.
Cmd ". M indicates the minute ~ 59), H indicates the hour 0 ~ 23), D Indicates Day 1 ~ 31), m represents Month 1 ~ 12), d indicates the day of a week ~ 6, 0 is a week
Days ). Cmd indicates the program to run. It is sent to sh for execution. The Shell contains only three environment variables: USER, HOME, and SHELL.
4. Description
Compared with the at command, the crontab command is suitable for tasks with a fixed cycle.
5. Application Instance
Set a scheduled and scheduled system prompt:
[Cao @ www cao] # crontab-e
The system opens a vi editor.
If you enter the following content: 35 17 ** 5 wall "Tomorrow is Saturday I will go CS", then save the disk and exit. At this time, a cao file will be generated in the/var/spool/cron/directory. The content is as follows:
# Do not edit this file-edit the master and reinstall.
#(/Tmp/crontab.2707 installed on Thu jan1 22:01:51 2004)
# (Cron version -- $ Id: crontab. c, v 2.13 1994/01/17 03:20:37 vixie Exp $)
35 17 ** 5 wall "Tomorrow is Saturday I will play CS"
In this way, a terminal will pop up at every Friday to remind you to play CS on Saturday! The result is shown in figure 3.
Figure 3 scheduled and scheduled system prompts
Hands-on exercises
1. Use kill and top commands to observe system performance changes.
Start a terminal to run the top Command, and then start a terminal to run the kill command, as shown in figure 4.
Figure 4 effect of kill command on top Terminals
In this case, use the kill command described above to abort some programs:
# Kill SIGKILL XXX
Then let's look at the changes in the top command terminal, including memory capacity, CPU usage, and system load. Note: Some processes cannot be aborted, but you can try it when learning Linux commands to see how the system responds.
2. Use the at and halt commands for Timed Shutdown
First, set the Shutdown Time To. Enter the following code:
# At 17: 35
Warning: commands will be executed using (in order) a) $ SHELL B) login shell c)/bin/sh
At> halt '-I-p
At>
Job 6
This
In fact, it has already entered the Linux system Shell, and compiled a simplest program: halt-I
-P. The text terminator in the Shell above indicates to press the Ctrl + D key combination to close the command and submit the task to exit the Shell. "Job 6
"" Indicates that the system accepts 6th at commands and runs the command at ",": First stop all network-related devices, shut down the system, and then turn off the power.
3. Use the crontab command to perform daily scheduled virus scanning
We have introduced a simple crontab command operation. Here we will look at some more important operations.
1) create a file and set the file name. Assume It is caoproject:
# Crontab-e
2) The file content is as follows:
05 09 *** antivir
After editing with vi, save the disk and exit. Antivir is a software that detects and removes Linux viruses. It must be installed in the system first.
3) use the crontab command to add it to the task list:
# Crontab caoproject
In this way, all users in the system will automatically scan the virus at 09:05 every day.
4. Use kill to make the modified configuration file take effect immediately
Windows users generally know that after an important configuration file is modified, the computer must be restarted to make the modification take effect. Because of the modular design, Linux can set services in real time as needed. Here we will take the network service inetd as an example to introduce some operation skills.
Inetd
Is a listening daemon that monitors connection requirements with Internet service processes such as rlogin, telnet, ftp, and rsh, and extends the required service processes. By default,
The daemon monitored by inetd is listed in/etc.
/Inetd. conf file. Edit the/etc/inetd. conf file to change the options for inetd to start the server daemon, and then drive inetd
SIGHUPsignal 1) sends a signal to the current inetd process to repeat the file. This process is implemented by the kill command.
After modifying inetd. conf in vi or another Editor, run the following command:
# Ps-ef | grep inetd
The code above indicates the process number (PID) for querying inetd. conf, which is assumed to be 1426, and then run the following command:
# Kkill-1426 inetd
In this way, the configuration file takes effect.
The system management commands described in this lecture are all important, especially the crontab and quota commands, which are difficult to use and require more exercises. In addition, pay attention to the "-9" parameter when using the kill command. It is best not to run some important programs during the exercise.
We hope the above Linux commands will help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.