Linux boot tasks and scheduled Tasks crontab

Source: Internet
Author: User

OS mainly has single-user single-task, single-user multitasking, multi-user multitasking several types. In multi-user multitasking operating systems, it is important to set up the environment for each user.

First, boot from the task.

Let's start with a clear idea of what the boot start is. The start-up task mainly occurs at two time points, one is the user does not log in before the system is starting the process, the other is the user successfully logged in (that is, through the login interface entered the user name password after landing).

1, before the user login, the system startup process automatically start the task

Basic knowledge: During system startup, when the kernel is loaded, the first program that executes is the/sbin/init,init program reads the contents of the Inittab file to determine the system's run level (0~6). After determining the run level, perform/etc/rc.d/rc.sysinit and initialize the system. The kernel module is then started. Execute the appropriate run-level file RC0.D~RC6.D after starting the kernel module. Then executes the/etc/rc.d/rc.local, and finally executes the/bin/login into the login state.

As we can see from the above, there are two ways to get the task started during system startup:

1) The start Script method can be in the/etc/rc.d/init.d file, and establish a link to the RC0.D~RC6.D.

INIT.D is stored in some of the services to run the system startup script, but not every script will be executed, the Linux system INIT.D services in the run-level RC0.D~RC6.D, after determining the operating mechanism of the system to execute the corresponding run-level RC? D

The Init.d script contains the full start, stop, reload, and status parameters. For example, to start an SSH service, you can enter SSH start in the terminal and terminate the SSH service to enter SSH stop in the terminal.

This is the recommended way to use it.

2) Put the startup script in/etc/rc/local,/etc/rc/local is executed after the other initialization script executes, the user can personalize the operation, set up the service that needs to start.

2, the user successfully login, automatically start the task

First look at the role of several files:

1)/etc/profile: This script is the setting of the global environment, which is valid for each user in the system, and executes the/etc/profile script immediately after each user logs in. Therefore, the tasks to be performed regardless of which user logged on are placed in this script.

2) ~/.bash_profile: It is the user home directory of the private environment settings, only for a specific user is valid, that is, a user login will execute its own corresponding home directory of the. Bash_profile script, with which users can personalize.

3)/ETC/BASHRC: Valid for all users, this script executes when the shell is opened, and he holds information about the System bash shell.

4) ~/.BASHRC: Valid for a particular user, executes this script every time the user opens a shell.

The difference between/etc/profile and ~/.bash_profile, and/ETC/BASHRC and ~/.BASHRC, can be understood as the difference between a global variable and a local variable in a program, similar in principle.

As a result, user settings automatically start tasks that can be selectively placed in the files above.

Second: Scheduled execution of tasks

Crond is a command that Linux uses to execute programs on a regular basis, and he periodically checks to see if there are tasks to perform, and if so, to perform the task. Crontab is a timed task trigger under Linux.

Several files related to cron and their functions are as follows:

1)/etc/cron.deny: The user listed in this file is not allowed to use the crontab command

2)/etc/cron.allow: Users listed in this file are allowed to use the crontab command

3)/var/spool/cron: crontab files for all users

The CRONTAB-E command is used to edit the current user's crontab file

crontab files are formatted as: * * * * *, the first paragraph represents the minute, the second paragraph represents the hour, the third paragraph represents the date, the fourth paragraph represents the month, and the fifth paragraph represents the week (0 = Sunday)

For example, to input the system's time into the testdata file every minute, simply add the */* * * * * Date>>testdata to the crontab file. Open the TestData file to find out that the system is outputting time to the testdata file every minute.

Note: In a multiuser environment, each user has its own crontab file.

Linux boot tasks and scheduled Tasks crontab

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.