Linux add boot starter

  
                  

Use the chkconfig command to view the services (or programs) that are automatically started at different startup levels. The format of the command is as follows: chkconfig --list The possible output is as follows: openvpn 0: off 1: on... 6: Off (0-6 is the startup level; turn off/on is the automatic startup option for the service at the appropriate level) If you want to make changes to the autostart option, the command format is: chkconfig --level x name on/off zB chkconfig -- Level 5 openvpn off The above commands can query the services that the system can provide. If you want to start a program at boot time, you can use the following methods: Add the name of the software you want to start in the last line of the ~/.bash_profile file. Such as: "synergyc 192.168.0.154", then automatically run synergyc at boot time and connect with 192.168.0.154. The above content is my personal configuration, but found a problem: FC12 completes the system startup after logging in, that is to say, when the user login interface is entered, the synergyc has not yet started. So, (perhaps) Synergyc is not suitable for being installed in a Linux system that is used as a mouse-free client.

Run the program automatically in Red Hat Linux 1. Run the program automatically at boot time After Linux is loaded, it initializes the hardware and device drivers and then runs the first process init. Init continues the boot process according to the configuration file and starts other processes. Normally, modifying script files placed in /etc/rc or /etc/rc.d or /etc/rc?.d allows init to automatically start other programs. For example, edit the /etc/rc.d/rc.local file and add a line to the end of the file "xinit" or "startx" to enter X-Window directly after booting.

2. Automatically run the program when logging in. When the user logs in, bash first automatically executes the global login script created by the system administrator: /etc/profile. Then bash looks for one of three special files in the user's home directory: /.bash_profile, /.bash_login, /.profile, but only the first one found. Therefore, you only need to add commands to the above files according to actual needs to automatically run certain programs when the user logs in (similar to Autoexec.bat under DOS).

3. Run the program automatically when you log out. When you log out, bash automatically executes the personal logout script /.bash_logout. For example, adding the command "tar -cvzf c.source.tgz *.c" to /.bash_logout automatically executes the "tar" command to back up the *.c file each time you log out.

4. Running the program automatically on a regular basis Linux has a daemon called crond. The main function is to periodically check the contents of a set of command files in the /var/spool/cron directory and execute the commands in those files at the set time. Users can create, modify, and delete these command files through the crontab command. For example, if you create a file crondFile with the content "00 9 23 Jan * HappyBirthday", after running the "crontab cronFile" command, the system automatically executes the program ""HappyBirthday" every 9:00 AM on January 23 " means that regardless of the day of the week).

5. Run the program automatically at a time

The timed execution command at is similar to crond (but it only executes once): The command is executed at a given time, but it is not automatically repeated. The general format of the at command is: at [ -f file ] time , which executes all the commands given in the file at the specified time. You can also enter commands directly from the keyboard:

$ 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 At 12:00, automatically send a message titled "Have a lunch", and the content of the plan.txt file will be sent to Roger.

#!/bin/bash RESTART="........" #Write the corresponding service code START="......." STOP=". ........." case "$1" in restart) $RESTART echo "......" ;; start) $START echo "......" ;; STOP) $STOP

echo "......" ;; *) echo "Usage: $0 {restart ¦ start ¦ stop}" exit 1 esac

exit 1

After the script is written, you need to modify the permissions chmod u+x test.sh

First, the linux random startup service programs are in the /etc/init.d folder. In the file, all the files are script files (the script program simply writes the program to be run to a file so that the system can execute in order, similar to the autorun.dat file under windows), and the file in /etc There are also folders such as rc1.d, rc2.d all the way to rc6.d, these are different runlevels of linux, we generally enter the X windows multi-user running level is level 5, which is rc5 .d, the script file in this folder is to start randomly when running level 5. Service program. It should be noted that the files in each rc (1-6).d folder are actually a soft link to the files in the /etc/init.d folder (similar to the shortcuts in windows), that is, Say, in the /etc/init.d folder is the entire service program, and each rc (1-6).d only links to the corresponding service program that it needs to start!

To start scim (a program), we must first know where the scim program is, can be found with the locate command, scim is in /usr/bin/scim, where usr is for the user, bin is Linux shows the programs that can be executed. This way, I can write a script, put it in /etc/init.d, and then make a corresponding soft link in rc5.d. This script is actually very simple, just two lines:

#!/bin/bash /usr/bin/scim

The first line is to declare what terminal to run this script, the second line is The command to run.

One more thing to note is that in rc5.d, the name of each link starts with S or K. The beginning of S is that the system startup is started randomly, and the beginning of K is Not started randomly. In this way, you can know that if I want to start a service randomly, I can change the first letter K of the name to S. Of course, after changing S to K, the service cannot be started randomly. Therefore, my link is also called SXXX, so that the system can make it start randomly

Add a self-starting script

First put your own script in /etc/init.d, Then execute the following command:

update-rc.da start 90 2 3 4 5 . stop 90 0 1 6 .

where a is your script, note that there are two points.

A script example.

#!/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 ]

Copyright © Windows knowledge All Rights Reserved