How to add an automatic execution program under ubuntu
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 changes are placed in
/Etc/rc or
/Etc/rc. d or
/Etc/rc ?. D
Directory to enable init to automatically start other programs. For example, edit/etc/rc. d/rc. local file (this file is usually the last script started by the system). Add "xinit" or "startx" at the end of the file to directly enter the X-Window after the file is started.
2. automatically run the program upon Logon
When a user logs on, bash automatically executes the global logon script created by the system administrator:
/Ect/profile
Bash then searches for one of the three special files in sequence in the user's starting directory:
/. Bash_profile,
/. Bash_login,
/. Profile,
But only the first one found is executed. 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.
Bash automatically runs the personal logout script when logging out.
/. Bash_logout.
For example /. in bash_logout, add the command tar-cvzf c. source. tgz *. c, the "tar" command is automatically executed every time you log out to back up *. 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, create a crondFile with the content "00 9 23 Jan * HappyBirthday". After running the "crontabcronFile" command, every time the system automatically executes the "HappyBirthday" program at AM on March 23, lunar January ("*" indicates that no matter the day of the day is the day of the week ).
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
At, an email entitled "Have a lunchtasks, containing the plan.txt file was automatically sent to Roger.
Add a boot script under Ubuntu
After Ubuntu is started, it will execute the script in the/etc/rc. local file, so we can directly add the startup script in/etc/rc. local.
Of course, you must add it to the statement before exit 0.
For example:
Sudo vi/etc/rc. local
Then add the script code before exit 0.
Later, I will try again to add a startup service for Ubuntu.
If you want to add a script file for startup, copy the script or connect it to/etc/init first. d/directory, and then use the: update-rc.d xxx defaults NN command (NN For the startup order) to add the script to the queue for initialization execution.
Note: If the script needs to use the network, NN needs to set a relatively large number, such as 98.