I am using below script to mask a file, I am passing source and destination file as argument.
#!/bin/bash
awk '
BEGIN {
IGNORECASE = 1
}
$1 ~ /^(self-signed-cert:|encrypted-cert-password:|self-signed-cert:|public-cert:|publicKey:|aes-encrypted-symmetricKey:)$/ {
gsub( /[^-]/, "X", $2 )
}
{ print }
' "$1" >"$2"
When i run below command from command script this works fine , and its generating masked file.
./mask.sh /opt/aaa/bbbb/file.yml /aaa/ccc/conf/msk.yml
But when i try running bash script from java code i get error -
bash.execute(new String[]{"sudo", "/scriptlocation/scripts/mask.sh" + " " + "/opt/aaa/bbbb/file.yml" +" "+ "/aaa/ccc/conf/msk.yml"});
Error : Could not execute bash command. Error: We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
- Respect the privacy of others.
- Think before you type.
- With great power comes great responsibility.
sudo: no tty present and no askpass program specified, input:
this is part of implementation of execute() method in Bash class
public int execute(String[] command) {
int returnCode = 1;
String strInput = null;
String strError = null;
StreamGobbler in = null;
StreamGobbler err = null;
try {
Process p = getRuntime().exec(command);
in = getStreamGobbler(p.getInputStream(), StreamGobbler.OUTPUT);
err = getStreamGobbler(p.getErrorStream(), StreamGobbler.ERROR);
in.start();
err.start();
returnCode = p.waitFor();
}