首页 > 其他 > 详细

rc.local里指定用户来运行程序

时间:2016-08-04 19:52:53      阅读:271      评论:0      收藏:0      [点我收藏+]

CentOS 6.5测试发现,rc.local里不能使用sudo,可以使用su

但有个前提条件,指定的用户可以不用建立家目录,但必须是可以登录的

[root@Lab2 ~]# vim /etc/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.


/bin/su - svn -c "svnserve -d -r /application/svndata/"


重启后

[root@Lab2 ~]# ps -ef|grep svn

svn       1561     1  0 11:52 ?        00:00:00 svnserve -d -r /application/svndata/

root      1603  1583  0 11:53 pts/0    00:00:00 grep svn


有些网友的笔记是用su <user>这种形式(少了一个-号),其实也是可以启动的,但是否用-号还是有些区别的

不带-号

[root@Lab2 ~]# su svn

[svn@Lab2 root]$ echo $PATH

/application/mysql/bin:/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


带-号

[root@Lab2 ~]# su - svn

[svn@Lab2 ~]$ echo $PATH

/application/mysql/bin:/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/svn/bin


PATH路径有所不同,只有带减号才算是完整的切换身份。

rc.local里指定用户来运行程序

原文:http://coosh.blog.51cto.com/6334375/1834262

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!