0

I'm using JSch in Android to create an SSH connection to execute a command and store in a string the result of this execution. I succeeded, but I have a problem.

If I run a command with "sudo" in the string is NOTHING stored. IN fact what is happening is that the system is asking for the sudo password, but I do not know how to send this command.

Do you know any way to do this?

I hope I explained well.

Paul9999
  • 751
  • 1
  • 11
  • 26

1 Answers1

0

The versions of sudo I am familiar with do not offer an option to provide the password on the command line, but they do offer an option to read the password from standard input. You can combine that with I/O redirection to feed the password to sudo without user interaction:

sudo -S do_stuff -a -b -c <<END
secret_password

END

Note that sudo wants the password to be terminated by a newline.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157