1. Run the program automatically at power-on startup
After Linux is loaded, it initializes hardware and device drivers, and then runs the first process init. Init continues the boot process based on the configuration file to start another process. Typically, modifications are placed in/ETC/RC or/etc/rc.d or/ETC/RC? The script file in the D directory allows Init to start other programs automatically. For example: Edit/etc/rc.d/rc.local file, at the bottom of the file with a line "Xinit" or "startx", you can start directly after the boot into the X-window.
2. Automatically run programs at logon
when a user logs on, bash first automates the global logon script created by the system administrator:/ect/profile. Bash then finds one of the three special files sequentially in the user's home directory:/.bash_profile,/.bash_login,/.profile, but only the one found first.
Therefore, simply adding a command to the above file in the light of the actual need enables the user to automatically run certain programs (similar to the DOS Autoexec.bat) when they log in.
3. Automatically run programs when you exit logins
When you exit login, Bash automatically executes the personal exit logon script/.bash_logout. For example, by adding the command "Tar-cvzf c.source.tgz *.c" in/.bash_logout, the "tar" command is automatically backed up *.c files each time you exit the login.
4. Automatically run programs on a regular basis
Linux has a daemon called crond, which periodically checks the contents of a set of command files in the/var/spool/cron directory and executes the commands in those files at set times. Users can create, modify, and delete these command files through the crontab command.
For example, the establishment of a document Crondfile, content of "9 hours * happybirthday", running the "crontab cronfile" command, every 23rd 9:00 system automatically executes the "HappyBirthday" program ("*" It means no matter what day of the week it is.
5. Scheduled automatic running of the program once
the timed execution command at is similar to Crond (but it only executes once): The command executes at a given time, but does not automatically repeat. The AT command is in the general format: at [-F file] time, executing all the commands given in the file at the specified times. You can also enter commands directly from the keyboard:
The code is as follows |
Copy Code |
$ at 12:00 At>mailto Roger-s″have a lunch″< plan.txt At>ctr-d Job 1 at 2000-11-09 12:00 |
three ways to set up a service from startup
This is done mainly in three different ways:
Ln-s a soft link to the/etc/init.d/service in the/ETC/RC.D/RC*.D directory (* represents one of the seven running levels of 0~6)
Chkonfig command line Run level setting
NTSYSV pseudo-graphics run level setting
Attention:
1. These three approaches are mainly used in Redhat distributions
2. If you do not know what the operation level is, then it is best to look at the relevant data before the experiment
The first way: Ln-s set up to start soft connections
There are 7 levels of running in Linux (available in/etc/inittab file settings), and each run level corresponds to the 7 directories of/ETC/RC.D/RC[0~6].D
Tips: /ETC/RC[0~6].D is actually a soft connection to the /etc/rc.d/rc[0~6].d , primarily to maintain compatibility with UNIX.
In these 7 directories, each directory holds a service that needs to be shut down or started when the run level is loaded.
From the detailed information can be known, in fact, each script file corresponds to the /etc/init.d/ directory Specific Services
The script file at the beginning of K represents the need to close when the run level is loaded, and the representative at the beginning of s needs to perform
So, when we need to start our own script on the boot, just drop the executable script in the /etc/init.d directory, and then create a soft link in the /etc/rc.d/rc*.d
LN -s/etc/init.d/sshd/etc/rc.d/rc3.d/s100ssh
Here sshd is the script file for the specific service, S100SSH is its soft link, S starts at load time
If you need to set up a self-boot at more than one run level, you need to set up multiple soft links
This is a tedious way to apply custom service scripts
If some services already exist on the system (such as the HTTPD service item when you install Apache), you can use the following two ways
The second way: Chkconfig
If you need to start some services yourself, simply use the chkconfig service name on, and if you want to turn off, change on to OFF
By default,Chkconfig will start 2345 These four levels, and if you want to customize, you can add --level options
Let's first turn off all the startup levels for the SSHD service and then start the custom level with the --level option
Tips: The --list option to view the startup status of the specified service,chkconfig View all service statuses without any options
The third Way: Ntsysv pseudo Graphics
ntsysv and chkconfig are the same, but they're just adding graphics.
There are two ways to start Ntsysv , one is to enter the NTSYSVdirectly on the command line, the second is to use the Setup command, and then select System Services
By default, what is the current run level, and what is the level of startup service set in ntsysv ?
For example, my current level of operation is 3, then I choose to start the service in the pseudo graphical interface, it will run a level of 3
If you want to customize the run level, you can use the ntsysv--level method
All three of these operations require that the service script file be executable and have root permissions
Where the first one is more for custom scripting, and the second to third for services that already exist in the system
such as FTP, samba, ssh, httpd, etc.
And, to do the relevant settings need to understand the operational level of the problem
Tips: If you want to start a service manually, the traditional way is to /etc/init.d service name start
You can actually do that,service name start