1

My shell script tries to run java in Amazon EMR which, when executed by a non-root user, always triggers this error:

/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

But when a shell script provided out-of-the-box is executed (same java) by a non-root user, it will gain full access to:

/var/log/spark/spark-hadoop-org.apache.spark.sql.hive.thriftserver.SecureHiveThriftServer2-1-ip-172-31-19-53.out

how does it do that? How to make my shell script also doing the same?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
tribbloid
  • 4,026
  • 14
  • 64
  • 103
  • Possible duplicate of [Changing to root user inside shell script](http://stackoverflow.com/questions/11636840/changing-to-root-user-inside-shell-script) – rkachach Oct 07 '15 at 07:18

2 Answers2

0

There are several options:

  1. Using the runuser command to launch your scrip as root:
 runuser -l  userNameHere -c '/path/to/command arg1 arg2'
  1. Using the su command:
su - 
  1. Using the sudo command

The following link provides several examples of the above commands:

http://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
rkachach
  • 16,517
  • 6
  • 42
  • 66
0

You should set the SUID bit of your script:

  1. Make root be the owner of your script.
  2. Allow "other" to execute it.
  3. Set the SUID bit.

Thus the script will be launched by anyone but be owned by root. Some links:

(browse for "suid bit")

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Thomas Baruchel
  • 7,236
  • 2
  • 27
  • 46