Automatically run the program in Red Hat Linux

Source: Internet
Author: User

Automatically run the program in Red Hat Linux


1. automatically run the program at startup
After Linux is loaded, it initializes the hardware and device drivers, and then runs the first process init. Init starts other processes based on the configuration file. Normally, the modification is placed in/etc/rc or/etc/rc. d or/etc/rc ?. The script file in the d directory can enable init to automatically start other programs. For example, to edit the/etc/rc. d/rc. Local file, add "xinit" or "startx" at the end of the file. You can directly enter X-window after the file is started.

 

First, all the services started randomly in Linux are in/etc/init. d. All the files in this folder are script files (in simple words, the script program writes the program to be run to a file so that the system can execute it in order, similar to Windows Autorun. in addition, there are folders such as rc1.d, rc2.d to rc6.d In the/etc folder, which are different runlevels in Linux, generally, the running level of multiple users in X Windows is 5th, that is, rc5.d. The script file in this folder is the service program to be started randomly when the script file is 5th. Note that in each RC (1-6 ). the files in the D folder are all/etc/init. A soft connection to the files in the D folder (similar to the shortcut in Windows), that is, in/etc/init. the D folder contains all the service programs, and each RC (1-6 ). d. Only link it to start the desired service program!

To start scim (a program), we first need to know where the scim program is. We can use the locate command to find it. scim is in/usr/bin/scim, the USR table indicates that the user belongs to the user, and bin indicates that the program can be executed in Linux. In this way, I can write a script program, put it in/etc/init. d, and then make a corresponding soft link in rc5.d.

2. automatically run the program upon Logon
When a user logs on, bash automatically runs the global logon Script:/etc/profile created by the system administrator. Bash then searches for one of the three special files in sequence in the user's starting Directory:/. bash_profile,/. bash_login, And/. profile, but only executes the first one found.
Therefore, you only need to add commands to the above files as needed to automatically run certain programs (similar to autoexec. BAT in DOS) during user logon ).

3. automatically run the program upon logon.
When you log out, bash automatically runs the personal logout script/. bash_logout. For example /. add the command "Tar-cvzf C. source. tgz *. C ", the system will automatically execute the" tar "command to back up every time you log out *. c file.

4. Periodically run the program automatically
Linux has a daemon called crond. Its main function is to periodically check the content of a group of command files in the/var/spool/cron directory, and execute the commands in these files at the specified time. You can use the crontab command to create, modify, and delete these command files.
For example, after you create a crondfile with the content "00 9 23 Jan * happybirthday" and run the "crontab cronfile" command, the system automatically runs the "happybirthday" Program ("*" indicates that no matter the day of the day is the day of the week) at AM on November 23, lunar January ).

5. automatically run the program once at a scheduled time
Scheduled command execution at is similar to crond (but it is only executed once): The command is executed at a given time, but is not automatically repeated. The at command is generally in the format of at [-F file] time. All commands in the file are executed at the specified time. You can also enter the command directly from the keyboard:

$ At 12: 00
At> mailto Roger-s "have a lunch" <plan.txt
At> CTR-d
Job 1

An email titled "have a lunch" is automatically sent to Roger at, containing the plan.txt file.

 

Related Article

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.