• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

issue in passiing variable to shell script

 
Murthy Manchala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send password to a shell script to run batch jobs.

I am not able to send password to shell script via java standalone application. the java main method cannot return value as its return type is "VOID". please advice me how i can get password in shell script though java standalone.

Due to security i can't use system out or i can't write to a file.

I saw below code in google but its not working for me
Test.java:


test.sh

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Murthy Manchala wrote:I saw below code in google but its not working for me

We really need you to tell the details. Just stating that something does not work for you does not help us in any way. The problem could be anywhere.

Based on the code you posted, I noticed two problems with the shell script:

On line 1 you have a space immediately following the = sign. With that space there you should have received an error message along the lines of "murthy not found" or something like that. Take the space out.

On line 2 you do not have a space between the echo keyword and the $out variable. Without that space Unix will concatenate the two words together, and try to execute echomurthy, which is not a command.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beside Andrews hints, I have the impression that you try to solve the problem on the basis of bad information.

Murthy Manchala wrote:I am trying to send password to a shell script to run batch jobs.


That's in general not the way to do it. You use the sudoers file instead, which has a nopasswd-option, if possible, alias for linux tasks. Are we talking about linux, by the way?

Due to security i can't use system out or i can't write to a file.
I saw below code in google but its not working for me
Test.java:


In my impression this is just System.out, which you want to avoid.

But how else would you like transfer to transfer the password? It's not just, that java returns void (you may use System.exit, to pass an int), but the caller is only able to receive an int.

Passing the output is a differnt mechanism, but not suitable for password-transfer.

As you mentioned yourself, it can be observed, and it can even be observed in the class-file without executing it (man strings). You may encrypt it, but then you need another password, so you're catched in a devils circle.
 
Murthy Manchala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried below code


Its printing nothing. If i put system.out it is printing the murthy. Is there any way i can get the ret_value in script.

Thanks


 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use System.out, which is not secure, or more complicated ways, which aren't more secure - just more complicated.

For which programs do you need the password? Are we talking about linux?

 
Murthy Manchala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need passord in shell script. In Unix.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here http://www.gratisoft.us/sudo/man/sudoers.html you find a description of the sudoers file.

The user murthy can run cmdToRun as any user without giving a password.

It may be wise to restrict the command to the bare minimum, i.e. maybe not the script itself, but critical commands inside the script.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Murthy Manchala wrote:Its printing nothing. If i put system.out it is printing the murthy.

What "it" are you talking about here?

Is "it" the Java program? In which case you are correct - without you telling it out send something to System.out or System.err you will not see any output from the Java program. And neither will the Shell script.

Is "it" the shell script? In which case the shell script you are referring to shows that you are getting the output from the Java application into the Shell script. In line 18 of your listing above, you run the Java application, and store it's output in the "out" variable. In line 19 you display the output on screen. So if you do see "murthy" on screen when running the script, then you already have the ret_value in your script.

Please, please, please pay attention to Stefan's posts. Creating an application in this manner that outputs the password is such an incredibly bad idea that you could end up getting in big trouble at your work when someone discovers what you have done (especially if they find out because their systems have been hacked, and especially if they also discover that you have been told many times that this is a bad idea).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic