How to execute commands at startup
How to execute a command or run a program at startup, and try several times, each failed, so you can do it by referring to some materials.
Someone suggested to execute the corresponding command in. login, or in. bashrc (using tcsh
Shell in. tcshrc. This is not acceptable ,. login is executed during user logon. You may not need to log on locally, or remotely log on to multiple users and log on multiple times. tcshrc is executed when the shell is started. After logon, the user usually opens the shell multiple times, so that the command or program will be executed multiple times.
Linux Startup sequence:
1. BIOS self-check
2. Run the system kernel and check the hardware
3. Run the system's first process init
4,
Init reads the information in the system boot configuration file/etc/inittab for initialization
/Etc/rc. d/rc. sysinit ------ system initialization script
/Etc/rc. d/rcX. d/[KS] * ------ configure the service according to the running level
/Etc/rc. d/rc. local --------- execute special local configuration
Others --------- special services at different running levels
In Linux, The init program is started to initialize the program. One concept related to the startup is the running level, and the running level is the current operating level of the operating system, you can define the Startup Program of the running level at different running levels. The system running level can be specified in the/etc/inittab file, the running-level programs run through the source/etc/rc. d/init. d. Link to the destination/etc/rcX. d. Here, X is the default running level of the system. Therefore, the default startup script is placed in/etc/rc. d/init. d.
# The default running level is as follows:
#0-stop (do not set initdefault to 0)
#1-
Single User Mode
#2-multiple users, but no NFS
#3-full multi-user mode
#4-useless
#5-X11
#6-
Restart (do not set initdefault to 6)
#
Detailed explanation of each running level:
0 indicates that the machine is shut down.
1 is the single-user mode, just like the security mode in Win9x.
2: multi-user mode, but no NFS
Yes.
3 is a complete multi-user mode, which is a standard operation level.
4
Generally, you do not need it. In some special cases, you can use it to do something.
For example, you can switch to this mode to make some settings when the battery of your laptop is exhausted.
5 is X11.
Window System.
6. Restart the init 6 server.
There are two ways to enable the system to run a specified program at startup: Step 4 in the startup sequence.
One way is to configure the service according to the running level.
One way is to execute special local configurations.
For example, when a task is started, run the command cvslockd:
Method 1:
1. Create a self-starting script/etc/rc. d/init. d/cvslockd with the following content:
#! /Bin/bash
/Usr/local/bin/cvslockd
Set the file attributes to executable:
# Chmod + x/etc/rc. d/init. d/cvslockd
2. view the computer running level. If you see id: 5: initdefault: in the file/etc/inittab, the system running level is 5.
3. in the/etc/rc5.d directory, make a soft connection to the executable file you want to execute, and start with the uppercase letter "S" when naming the file, the number size after S indicates the order of execution. The larger the number, the higher the execution order.
# Ln
-S/etc/rc. d/init. d/cvslockd/etc/rc5.d/S100cvslockd
# Ln-s
/Etc/rc. d/init. d/cvslockd/etc/rc0.d/K20cvslockd
Method 2:
Add exec in/etc/rc. d/rc. local
/Usr/local/bin/cvslockd
This method starts cvslockd at the end.
Original document reference