Pritom
Pritom

Reputation: 1333

How do you set user work as root in Linux, when the bash script runs via Java code

Suppose my bash file contains

chmod -R 777 $backup_files/app/webroot/uploadedFiles/

It works fine when I run it through root permission using /permission.sh but when I try to run this bash script via java code like

        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("/permission.sh");
        printBufferedReaderOutputFromProcess(process);
        process.waitFor();

It gives me the following error:

chmod: changing permissions of `/home/app/webroot/uploadedFiles/A.jpg': Operation not permitted 

What can I fix it?

Upvotes: 1

Views: 899

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533510

I suspect you haven't use sudo before, however an alternative to using the setuid on the script is to give the user the right to sudo the script as root. i.e.

sudo permisions.sh

This runs as root can can be run without asking a password. You have to set this up in sudoers.conf

Upvotes: 1

ziesemer
ziesemer

Reputation: 28687

How are you running your Java code? Is it stand-alone, or running in a web container like Tomcat? If the later, it's probably running as a user that doesn't have permissions to the directory you're trying to change.

Upvotes: 0

Related Questions