

免费资源网 – https://freexyz.cn/
今天公司同事来找到我说要在服务器上用另外一个用户执行python脚本,但设置到crontab里却老是root用户来执行,为了省事我就想了一个偷懒的办法,就是用shell脚本切换到那个用户,然后去执行那个python脚本.好了,这篇文章我只演示怎么用shell脚本切换到其他用户执行命令.
系统:centos 5.x
脚本内容:
cat test.sh
复制代码
代码如下:
#!/bin/bash
su – test <
pwd;
exit;
EOF
执行结果图:
当然也可以用下面的命令来执行
代码如下:
su – test -c “pwd”
ps:
切换用户只执行一条命令的可以用: su – oracle -c command
切换用户执行一个shell文件可以用:su – oracle -s /bin/bash shell.sh好了,就这样吧.
免费资源网 – https://freexyz.cn/
© 版权声明
THE END
暂无评论内容