您的位置:首页 > 其它

ubuntu开机自动执行脚本

2014-09-04 10:43 357 查看
想要在开机的时候用指定的用户来启动脚本可以结合rc.local文件和su命令。

su命令:

su – 用户名 -c 命令

‘su’ 和 ‘su -’ 的区别是’su -’切换用户的同时也切换了环境变量,所以一般推荐使用 ‘su -’

‘-c’ 后面接要执行的命令

则以上命令实现先切换到指定用户,执行命令,再切换回原来的用户。

rc.local文件一般为开机最后执行的。编辑/etc/rc.local文件:

view
source

01
#!/bin/sh
-e
02
#
03
#
rc.local
04
#
05
#
This script is executed at the end of each multiuser runlevel.
06
#
Make sure that the script will "exit 0" on success or any other
07
#
value on error.
08
#
09
#
In order to enable or disable this script just change the execution
10
#
bits.
11
#
12
#
By default this script does nothing.
13
 
14
#以下为加入的脚本
15
su
 
-
kurenai -c 
/home/kurenai/tomcat/bin/startup
.sh
16
#
17
 
18
exit
 
0
19
~                                                                              
20
~                                                                              
21
~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: