Reputation: 81
I'm trying to execute a Linux shell script through my java program and i'd like my script to take as argument the root's password. As my Linux knowledge goes i know that if i make the command sudo apt-get update -y
he updates everything without prompting me for confirmation.
Is there any way to make the same but with the password? Whenever the script prompts for password he automatically reads the argument and inputs it?
EDIT: If i create a script to execute my jar file with sudo (ex: sudo javac -jar /mnt/raid/program.jar), do my scripts called upon get sudo rights aswell? As of an inheritance.
Upvotes: 1
Views: 162
Reputation: 46
Sudo has the -S argument. From the sudo man page:
The -S (stdin) option causes sudo to read the password from
the standard input instead of the terminal device. The password
must be followed by a new-line character.
You could do something like:
echo PASSWORD | sudo -S COMMAND
Upvotes: 3