我的shell脚本尝试在Amazon EMR中运行java,当由非root用户执行时,它总是会触发此错误:
/usr/lib/spark/sbin/spark-daemon.sh: line 153: /var/log/spark/spark-hadoop-org.apache.spark.sql.hive.thriftserver.SecureHiveThriftServer2-1-ip-172-31-19-53.out: Permission denied
failed to launch org.apache.spark.sql.hive.thriftserver.SecureHiveThriftServer2:
tail: cannot open ‘/var/log/spark/spark-hadoop-org.apache.spark.sql.hive.thriftserver.SecureHiveThriftServer2-1-ip-172-31-19-53.out’ for reading: No such file or directory
但是当非root用户执行开箱即用的shell脚本(相同的java)时,它将获得对以下内容的完全访问权限:
/var/log/spark/spark-hadoop-org.apache.spark.sql.hive.thriftserver.SecureHiveThriftServer2-1-ip-172-31-19-53.out
它是怎么做到的?如何使我的shell脚本也这样做?
答案 0 :(得分:0)
有几种选择:
runuser -l userNameHere -c '/path/to/command arg1 arg2'
su -
以下链接提供了上述命令的几个示例:
http://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/
答案 1 :(得分:0)
您应该设置脚本的SUID位:
因此,脚本将由任何人启动,但由root拥有。一些链接:
(浏览“suid bit”)