Automatically run programs in red Hat Linux

Source: Internet
Author: User
Tags linux

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:

$ 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.? 9 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. Er Ger Er

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.