2

We are doing some testing and need to run a java program as a user other than root. This is on a CentOS 6.5 box. with java 8. The script calls and executes the java program. I did the following on that script without any luck.

chown user:user script chmod 06755 script 

This still runs the process as root. The following is the part of the script that calls the java program and generate the process. What would be the best way to get this to run as the user instead of root.

#SHOWCLASSES="-verbose:class" SHOWCLASSES= exec /opt/jdk32/bin/java $SHOWCLASSES -Xms80M -Xmx120M com.integra.linkage.ProgramDirector "$@" 

When I try and run the script with this modification i get this following error

su -c "exec /opt/jdk32/bin/java $SHOWCLASSES -Xms80M -Xmx120M com.integra.linkage.ProgramDirector "$@"" -s /bin/sh esadmin ProgramDirector: No operational mode chosen. Usage: ProgramDirector [-wsdl programname ...] -wsdl - Generate a WSDL file programname - The name of one or more program classes -mcs - Connect to MCS and wait for messages. 
9
  • 1
    This isn't fit for SO because it is not programming-related. Anyways, make sure it isn't setuid root. Commented Jul 14, 2015 at 14:53
  • @m0skit0 I disagree. We have linux tags for just such a question. In fact, I'd even say this is a dupe of a very well established question: stackoverflow.com/questions/6905697/… Commented Jul 14, 2015 at 14:59
  • 3
    @jkeuhlen: The referenced question was closed as off-topic, so this one should probably be closed, too. Commented Jul 14, 2015 at 15:09
  • I have tried the solution in the what you linked, and it is not working for me. Hence why I asked the question again. Commented Jul 14, 2015 at 15:35
  • @Thomas Good point not sure how I missed that. Still confuses me why something with over 100,000 views would be off topic. Commented Jul 14, 2015 at 15:51

1 Answer 1

3

As taken from how to run script as another user without password

Try using:

su -c "Your command right here" -s /bin/sh username 

Just changing the ownership of a file will not cause it to be run as that user, you are just saying who can run it (root can run everything). You need to execute the command as another user.

In response to your update, let's look at why it isn't picking up the arguments you pass in:

su -c "exec /opt/jdk32/bin/java $SHOWCLASSES -Xms80M -Xmx120M com.integra.linkage.ProgramDirector "$@"" -s /bin/sh esadmin 

I'm going to strip out the extra stuff to draw your attention to what matters here:

su -c "exec ... "$@"" -s /bin/sh esadmin 

You have four sets of unescaped double quotes! This is most certainly going to cause some problems. Instead, so you can avoid escaping the inner quotes, simple pass in your command with single quotes and try again:

su -c 'exec /opt/jdk32/bin/java $SHOWCLASSES -Xms80M -Xmx120M com.integra.linkage.ProgramDirector "$@"' -s /bin/sh esadmin 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.