Use the Chkconfig command to view services (or programs) that start automatically at different startup levels, with the following command format:
Chkconfig--list
The output may be as follows:
OpenVPN 0: Close 1: Open ... 6: Close (0-6 is the start level; Turn off/Open the automatic start option for the service at the appropriate level)
If you want to make changes to the Auto start option, the command format is:
Chkconfig--level x Name On/off
z.b. chkconfig--level 5 OpenVPN off
The above commands can query the service that the system can provide, if you want to start a program on startup, you can use the following methods:
On the last line of the ~/.bash_profile file, add the name of the software you want to start. For example: "Synergyc 192.168.0.154" will automatically run SYNERGYC and connect with 192.168.0.154 on power-on.
The above content for my personal configuration, but found a problem: FC12 after landing to complete the system startup, that is, when entering the user login interface Synergyc has not yet started. Therefore, (perhaps) SYNERGYC is not suitable to be installed in a Linux system that is used as a mouse-free client.
Automatically run programs in red Hat Linux
1. Automatically run the program 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 the program at logon
When a user logs on, bash first automates the global logon script created by the system administrator:/etc/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 the program when you exit the login
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. Regular automatic running of the program
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. Timed automatic Running 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:
$ at 12:00
At>mailto Roger-s″have a lunch″< plan.txt
At>ctr-d
Job 1 at 2000-11-09 12:00
2000-11-09 12:00 automatically issued a title "Have a Lunch", content for Plan.txt file content of the mail to Roger.
#!/bin/bash
Restart= "..." #里面写相应服务代码
Start= "..."
Stop= "....."
Case "$" in
Restart)
$RESTART
echo "..."
;;
Start
$START
echo "..."
;;
STOP)
$STOP
echo "..."
;;
*)
echo "Usage: $ {restart¦start¦stop}"
Exit 1
Esac
Exit 1
After the script is finished, you need to modify the permissions chmod u+x test.sh
First of all, Linux randomly started the service program in/ETC/INIT.D This folder, the files inside are all script files (the script is simply to run the program to write to a file to allow the system to execute sequentially, similar to Windows Autorun.dat files In addition, there are also folders in the/etc folder, called Rc1.d, rc2.d to RC6.D, which are different runlevel of Linux, and the level of the X Windows multiuser we typically enter is level 5th, That is rc5.d, the script file under this folder is the service program to start randomly when running level 5th. Note that the files under each RC (1-6). D folder are actually a soft connection to the files under the/etc/init.d folder (similar to shortcuts in Windows), that is, the entire service program under the/etc/init.d folder, and each RC ( 1-6). D link only the corresponding service program that it needs to launch itself!
To start SCIM (a program), we first need to know where the SCIM program, with the Locate command can be found, SCIM in/usr/bin/scim here, where the USR is the user's, bin in Linux to express the program can be executed. In this way, I can write a script, put it in the/ETC/INIT.D, and then make a corresponding soft link in the RC5.D.
This script is actually very simple, just two lines:
#!/bin/bash
/usr/bin/scim
The first line is the declaration of what terminal to run the script, the second line is the command to run.
It's also important to note that in RC5.D, each link's name begins with S or K, and s begins with a system startup that starts randomly, and K begins with a random start. In this way, you can know, if I want which service to start randomly, it is the first letter of its name changed to S on it, of course, the s changed to K, this service can not be started randomly. So I'm going to name this link as sxxx so the system can get it started randomly.
Add a self-starter script
First put your own script in the/ETC/INIT.D, and then execute the following instructions:
UPDATE-RC.D a start 90 2 3 4 5. Stop 90 0 1 6.
Where A is your script, notice that there are two points.
A script example.
The code is as follows:
#!/bin/sh
# Source function library.
if [-f/etc/init.d/functions]; Then
. /etc/init.d/functions
Else
. /lib/lsb/init-functions
Fi
Mod=/a.ko
Start ()
{
Echo-n $ "Insert a kernel module:"
/sbin/insmod $MOD
Echo
}
Stop ()
{
Echo-n $ "Remove a kernel module:"
/sbin/rmmod a-f
Echo
}
[f $MOD] | | Exit 0
# How we were called.
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart|reload)
Stop
Start
;;
*)
echo $ "Usage: $ {start|stop|restart|reload}"
The UPDATE-RC.D command, which is used to automatically upgrade the System V type initialization script, simply means what you want the system to run when booting the initialization, which is expected to stop on shutdown or reboot, and can be used to help you set it up. The scripts are connected in/etc/rcn.d/lnname, and the corresponding scripts are located in/etc/init.d/script-name.
1, set the specified boot sequence, specify the run level of the Startup items:
UPDATE-RC.D start
2, set at the specified run level, in the specified order to stop:
UPDATE-RC.D Stop
3. Remove the specified startup entry from all run levels:
Update-rc.d-f Remove
For example:
UPDATE-RC.D script-name Start 90 1 2 3 4 5. Stop 52 0 6.
Start 90 1 2 3 4 5. : Indicates that in 1, 2, 3, 4, 5 of these five run levels, in order, from small to large, the 90th runs this script.
Stop 52 0 6. : in 0, 6 of these two levels of operation, in order, from small to large, the 52nd to stop the operation of the script.
If you add a script to the/ETC/INIT.D, you need to create a link
In the/ETC/RC*.D. K begins with Kill, and S begins with start, and the numeric order represents the order of initiation. (SYSV)
UPDATE-RC.D can do you a favor.
Cases:
Create a script called Zope in the/ETC/INIT.D, and then
UPDATE-RC.D Zope Defaults
The following link is generated:
The code is as follows:
Adding system startup For/etc/init.d/zope ...
/etc/rc0.d/k20zope->. /init.d/zope
/etc/rc1.d/k20zope->. /init.d/zope
/etc/rc6.d/k20zope->. /init.d/zope
/etc/rc2.d/s20zope->. /init.d/zope
/etc/rc3.d/s20zope->. /init.d/zope
/etc/rc4.d/s20zope->. /init.d/zope
/etc/rc5.d/s20zope->. /init.d/zope
Other advanced use method please man UPDATE-RC.D