I just tried your script using the following command:

ssh localhost sh /Users/gnodet/work/tmp/myscript.sh

and I don't see the prompt either, so it may be the read command bypassing
the prompt when the input stream is not the console.

You could try the following:

#!/bin/sh
echo Welcome
echo -n "Please input your age: "
read age
echo You are $age years old

For the backspace, I think it's the same problem and read bypasses readline
if the input stream is not the console.

One limitation of sshd is about pty allocation : we can't use things such
as http://man7.org/linux/man-pages/man3/openpty.3.html so the only way to
have real interactive sessions is to have the input stream handled in java
using jline for example.  Unless you find a command that can be interactive
without using a real pseudo-terminal.




2014-04-29 19:02 GMT+02:00 Alexandre Gattiker <[email protected]>:

> Hello,
>
> Is it possible to run interactive shell scripts using Apache SSHD? My
> attempt was not very successful.
>
> Java code:
>
> SshServer sshd = SshServer.setUpDefaultServer();
> sshd.setPort(45121);
> String hostKey = new
> File(App.class.getResource("hostkey.pem").toURI()).getAbsolutePath();
> sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
> sshd.setShellFactory(new ProcessShellFactory(new String[] { "sh",
> "myscript.sh" }, EnumSet.of(TtyOptions.ONlCr, TtyOptions.ICrNl,
> TtyOptions.Echo)));
> List<NamedFactory<UserAuth>> userAuthFactories = new
> ArrayList<NamedFactory<UserAuth>>();
> userAuthFactories.add(new UserAuthPassword.Factory());
> sshd.setUserAuthFactories(userAuthFactories);
> sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
>     public boolean authenticate(String username, String password,
> ServerSession session) {
>         return true;
>     }
> });
> sshd.start();
>
>
> myscript.sh:
>
> #!/bin/sh
> echo Welcome
> read -p "Please input your age: " age
> echo You are $age years old
>
>
> The output of an SSH connection is only "Welcome" (the prompt does not
> appear). Then, I can input a value and the characters are echoed, but
> backspace doesn't work.
>
> Thanks in advance,
> Alexandre
>

Reply via email to