Chmod from Runtime.Exec

B

Brad Cooper

Hello All,
I have a interesting situation where I'm trying to run a shell script
test.sh from my web application (I have already informed my client of
the security risk assocaited with this).

I'm trying to do a simple chmod 777 before I try to execute the shell
script to insure that it has the execute bit is set.

So I do something similar to the below.

Process proc0 = Runtime.getRuntime().exec("chmod 777 test.sh");
//i check the file permissions using the os and it is changed
Process proc1 = Runtime.getRuntime().exec("test.sh");
//doesn't work

BUT if I run the same statements again from a 2nd web page IT works.

It's like in the same request that chmod mod didn't take effect, even
though at the OS level it did?

Anyone have any ideas?

Thanks,
Coop
 
S

Sudsy

Brad Cooper wrote:
Process proc0 = Runtime.getRuntime().exec("chmod 777 test.sh");
//i check the file permissions using the os and it is changed
Process proc1 = Runtime.getRuntime().exec("test.sh");
//doesn't work
<snip>

This would require the cwd (current working directory) be included in
the PATH. What happens if you change it to this:

Process proc1 = Runtime.getRuntime().exec("/bin/sh test.sh");

?
 
M

Mohun Biswas

Brad said:
Hello All,
I have a interesting situation where I'm trying to run a shell script
test.sh from my web application (I have already informed my client of
the security risk assocaited with this).

I'm trying to do a simple chmod 777 before I try to execute the shell
script to insure that it has the execute bit is set.

So I do something similar to the below.

Process proc0 = Runtime.getRuntime().exec("chmod 777 test.sh");
//i check the file permissions using the os and it is changed
Process proc1 = Runtime.getRuntime().exec("test.sh");
//doesn't work

BUT if I run the same statements again from a 2nd web page IT works.

It's like in the same request that chmod mod didn't take effect, even
though at the OS level it did?

Anyone have any ideas?

Thanks,
Coop

I cannot for the life of me see why you aren't running "sh test.sh"
instead of changing the permissions.

Also, remember that the concept "current working directory" doesn't
really exist in Java. Thus you should determine the actual location of
test.sh and run it with a full path.
 
B

Brad Cooper

Turns out it an Asynchronous problem. need to do a waitFor against the
process returned from exec method.

Thanks for the replies though.

Coop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top