In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use crontab command in Linux, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
crontab
1. role
The crontab configuration file can be modified using the crontab command, which is then executed by the cron utility at the appropriate time using permissions for all users.
2. format
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
3. main parameters
-e: Run a text editor to set the schedule, the default text editor is vi.
-r: Delete the current schedule.
-l: List the current timetable.
crontab
the format of the document is "M H D m d"
cmd"。where M represents minutes (0 - 59), H represents hours (0 - 23), D represents days (1 - 31), m represents months (1 - 12), d represents days of the week (0 - 6, 0 is week
God). cmd represents the program to run, it is sent to sh execution, this Shell only USER, HOME, SHELL three environment variables.
4. description
Compared to the at command, crontab is better suited for fixed-cycle tasks.
5. application example
Set a timed, periodic system prompt:
[cao @www cao]#crontab -e
A vi editor opens.
If you enter the following: 35 17 * * 5 wall "Tomorrow is Saturday I will go CS", then save to exit. At this point in the/var/spool/cron/directory will produce a cao file, the content is as follows:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.2707 installed on Thu Jan 1 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, every Friday at 17:35, the system will pop up a terminal to remind you that you can play CS on Saturday! The results are shown in Figure 3.
Figure 3. A timed, periodic system prompt
hands-on exercises
1. Use the kill and top commands together to observe changes in system performance
Start a terminal first to run the top command, and then start a terminal to use the kill command, as shown in Figure 4.
Figure 4 Observe the effect of kill command on top terminal
Use the kill command described above to abort some programs:
#kill SIGKILL XXX
Then look at the changes in the top command terminal, including memory capacity, CPU usage, system load, etc. Note that some processes cannot be aborted, but try learning Linux commands and see how the system reacts.
2. Use the at and halt commands for timed shutdown
First set the shutdown time to 17:35 and 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 at 2004-01-01 17:35
this
In fact, you have already entered the Shell of the Linux system, and wrote the simplest program: halt-i.
-p。The end of text symbol in the Shell above indicates that pressing Ctrl+D closes the command and submits the task to exit the Shell. "Job 6 at 2004-01-01
17:35"indicates that the system accepts the 6th at command and executes the command at"2004-01-01 17:35": stop all network-related devices first, shut down the system and then shut down the power supply.
3. Use crontab command to realize virus scanning at regular time every day
We've already covered a simple crontab command operation; here are some more important ones.
(1) Create a file, the file name is set by yourself, assuming caoproject:
#crontab -e
(2) The document reads as follows:
05 09 * * * antivir
Save and exit with vi. Antivir is a Linux virus detection software, of course, when necessary first installed in the system.
(3) Add to the task list using crontab command:
#crontab caoproject
All users in the system are automatically scanned for viruses at 9:05 a.m. every day.
4. Use kill to make the modified profile take effect immediately
Windows users generally know that important configuration file changes often require a computer restart for the changes to take effect. Linux, on the other hand, has a modular design that allows you to configure your own services in real-time as needed. Here is an example of inetd, a network service, to introduce some operational skills.
inetd
is a listening daemon that listen for requests to connect to process that provide Internet services (such as rlogin, telnet, ftp, rsh) and extends that required service process. By default,
These daemons that inetd listens on are 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 to
SIGHUP (signal 1) sends a signal to the current inetd process to cause inetd to reread the file. This is done by the kill command.
After modifying inetd.conf with vi or another editor, first use the following command:
#ps -ef |grep inetd
The above code indicates the process number (PID) of the query inetd.conf, which is assumed to be 1426, and then use the following command:
# kill -1426 inetd
This configuration file takes effect.
The system management commands introduced in this lecture are relatively important, especially the crontab command and quota command will be difficult to use, and need to do more practice. In addition, use the kill command to pay attention to the "-9" parameter, practice *** do not run some important programs.
Thank you for reading this article carefully. I hope that Xiaobian's shared article "How to use crontab command in Linux" will help everyone. At the same time, I hope everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.