Linux implementation automatically run normal user script

Source: Internet
Author: User

Since it is necessary to implement the boot Autorun script, it is related to the Linux boot-up service principle; When Linux is turned on, a step is taken to read the/etc/inittab configuration file, select the system runlevel, then initialize the system and execute the RC script under/etc/rc.d/. The/etc/rc.d/rc.local self-starter script is a script that Linux leaves the user to customize a personalized startup item.
All you have to do is open the script file and look at the explanations above, which clearly tells you what this script file does. The user can write a script here, the script will be executed automatically when booting, start the service program that you want to start.

[[email protected] ~]# cat /etc/rc.d/rc.local #!/bin/sh#This script will be executed *after* all the other init scripts.#You can put your own initialization stuff in here if you don‘t#want to do the full Sys V style init stuff.touch /var/lock/subsys/local[[email protected] ~]#

Programme one:
Use the /etc/rc.d/rc.local self-starter script file to enable automatic run of normal user scripts
There are two ways to implement this:
1, the need to boot the script program directly into the/etc/rc.d/rc.local file, this way will automatically execute these scripts, run the corresponding service program. Need to be edited in the root environment
2, first write the script, define a good path, and then use the SU command to execute, here just put the SU command into the/etc/rc.d/rc.local script file.
For example: I need to boot execute/home/ricky/bin/ricky.sh script, then add the following statement in/etc/rc.d/rc.local:
[[email protected]~]#echo "su - ricky -c ‘/bin/sh /home/ricky/bin/ricky.sh‘" >>/etc/rc.d/local
The execution path of the command must use absolute paths to prevent errors due to environmental variables.

Scenario Two:
We all know that all the files in the /etc/init.d/ directory are script files, and the script files in this directory will be executed automatically when the boot entry is set up.
Using the root account, self-initiated script editor (a startup script that is free to write)

[[email protected] ~]#vim /etc/init.d/networkstart#!/bin/bash#network start scripts#chkconfig: 235 80 30  --235指定的启动级别,在哪写启动级别下启动;--80 启动的优先级;--30 关闭的优先级service network start –-启动network服务(你也可以把普通用户脚本放这里,开机启动的时候就会执行;也可以定义好脚本路径,把执行脚本的命令放进这里)

The file default is not execute permission, so to adjust the script file permissions

[[email protected] ~]# chmod +x /etc/init.d/networkstart

You also need to add the boot entry settings to start the boot so that the script file takes effect

[[email protected] ~]# chkconfig --add networkstart 加入启动项[[email protected] ~]# chkconfig networkstart on   设置开机自启动

If you open a firewall, you have to turn off the firewall.

[[email protected] ~]# service stop iptables   关闭防火墙[email protected] ~]# setenforce 0 关闭SELinux

Linux implementation automatically run normal user script

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.