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. Run programs automatically when you log on
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. Run program automatically 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. Run programs automatically on a regular basis
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. Run the program automatically 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. Er Ger Er