开机自动启动脚本,通过root用户切换到不同用户执行命令
配置脚本auto.sh,通过切换不同用户执行命令
#!/usr/bin/expect -f
spawn su - test1 -c "mkdir /ceshi/test1"
spawn su - test2 -c "mkdir /ceshi/test2"
expect eof
1.移动脚本到/etc/rc.d/init.d/
mv /auto.sh /etc/rc.d/init.d/
2.增加脚本的可执行权限
chmod +x /etc/rc.d/init.d/auto.sh
3.添加脚本到开启自动启动项中
cd /etc/rc.d/init.d
chkconfig --add auto.sh
chkconfig auto.sh on
注意:
运行脚本提示
service auto.sh does not support chkconfig
脚本中需要增加以下两项
# chkconfig: 2345 10 90
# description: myservice ....
#!/usr/bin/expect -f
# chkconfig: 2345 10 90
# description: myservice ....
spawn su - test1 -c "mkdir /ceshi/test1"
spawn su - test2 -c "mkdir /ceshi/test2"
expect eof
重启后进入/ceshi 目录下,检查test1和test2目录是否创建
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。