How to start, log in, exit, schedule, and run programs automatically on Linux

Source: Internet
Author: User
Tags set time

1. Automatically run the program when booting up

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, starting other processes. 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 the/etc/rc.d/rc.local file, add a line at the bottom of the file "Xinit" or "startx", you can start the boot directly into the X-window.

2. Automatically run the program at login

When a user logs on, bash first automatically executes a global logon script created by the system administrator:/ect/profile. Bash then looks for one of three special files in the user start directory:/.bash_profile,/.bash_login,/.profile, but only one that was first found.
As a result, you can automatically run certain programs (similar to DOS Autoexec.bat) when a user logs on by simply adding a command to the above file according to the actual need.

3. Automatically run the program when logging out

When you log out, Bash automatically executes a personal logout logon script,/.bash_logout. For example, by adding the command "Tar-cvzf c.source.tgz *.c" to/.bash_logout, the "tar" command is automatically backed up *.c files each time you log out.

4, regular automatic operation of the program

Linux has a daemon called Crond, and 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 a set time. Users can create, modify, and delete these command files through the crontab command.
For example, to establish a file Crondfile, the content is "XX 9 Jan * happybirthday", after running the "crontab cronfile" command, the system automatically executes the "HappyBirthday" program ("*") every 23rd 9:00 The day of the week.

5, timed automatic operation of the program once

Timed execution command at is similar to Crond (but it executes only once): the command executes at a given time, but does not automatically repeat. The general format of the AT command is: at [-F file] time, all commands given in the file are executed 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 sends a message titled "Have a Lunch" to the content of the Plan.txt file to Roger. 9 12:00
2000-11-09 12:00 automatically sends a message titled "Have a Lunch", content for Plan.txt file content to Roger.

How to start, log in, exit, schedule, and run programs automatically on Linux

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.