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

需求描述:自己写的一个阿里云的挂载OSS的脚本,需要指定非root账号执行;

操作系统:CentOS release 6.8 


# vi /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

/bin/su - urs -c "/home/script/mount-oss.sh"


系统重启后:查看进程;

#ps -ef|grep urs

]# ps -ef|grep urs

root       731   668  0 10:59 pts/5    00:00:00 su urs

urs        732   731  0 10:59 pts/5    00:00:00 bash

urs       1322     1  0 11:11 ?        00:00:00 ossfs cuishou-record /home/cuishou-record -ourl=http://oss-cn-hangzhou-internal.aliyuncs.com


最好使用su - username 只有带减号才是完整的身份切换


猜你喜欢

转载自blog.51cto.com/xiexf/2166370
今日推荐