I am using a simple command to change password for user in remote linux machine by using Java Jsch code. My command is
command = "echo -ne "+userPassword+" \n echo "+userPassword+" \n | smbpasswd -a -s "+userId;
((ChannelExec)channel).setPty(true);
((ChannelExec)channel).setCommand("sudo -S -p '' "+command);
But it is returning error saying,
bash: command substitution: line 2: syntax error near unexpected token `|' bash: command substitution: line 2: ` | smbpasswd -a -s TestUserNew' sudo: JX7MuQoTJX7MuQoT: command not found
I am confused here as this command runs in Linux. Can someone please help me fix this?
Thanks, Gourab
This command works on the command line:
(echo "wxfLW2qJ"; echo "wxfLW2qJ") | sudo smbpasswd tester
Note that sudo
is used for the smbpasswd
command. Furthermore the brackets around the first part create a subshell which seems to be important.
I have solved the problem.
Original code is,
command = "echo -ne \\""+userPassword+"\\n"+userPassword+"\\n | sudo smbpasswd -a -s "+userId;
And the updated code is,
command = "echo -ne \\""+userPassword+"\\n"+userPassword+"\\n\\" | sudo smbpasswd -a -s "+userId;
Thanks everyone I have got lot of clues to solve this issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.