0

How can I wait until a shell prompt appears before further commands get executed (in a bash script e.g?) on some hosts I can do ssh user@host echo "test"; and it would login, and when ready execute echo "test" - but it looks like it doesn't work on every host. I would like to wait for the # or $ prompt to appear before continuing on to execute echo "test" - how can i do so?

When I do ssh user@host then wait for the # and manually do echo "test" it works as you would expect. How can I put this into a script? ssh user@host -t echo "test" doesn't work either.

I'm particularly trying to do something like: ssh -o StrictHostKeyChecking=no -p 2222 user@host -t tail -f /var/log/MyFile.log i.e. tail a log file of a host and show the result on the local shell Instead of tailing the log file, it just throws me to the prompt:

No entry for terminal type "screen";
using dumb terminal settings.
#

--> Please ignore that the prompt is root, that's not part of this thread. And yes, it is launched out of a screen session - from a plain terminal (xterm), it says No entry for terminal type "xterm"; (e.g.) instead.

Without -t I get FATAL: not a terminal and it throws me back to the local shell.

  • 1
    That'll never exit. Do you really want that? – roaima Dec 13 '19 at 20:16
  • @roaima yes I do, it will exit by Ctrl-C or reboot of the remote box - it's an embedded device, not a PC – stdcerr Dec 13 '19 at 20:17
  • 1
    On the remote machine, does the shell's startup file (probably ~/.bashrc) do something that actually requires a terminal, like start screen or use some other tool that requires a terminal? – Kusalananda Dec 13 '19 at 21:05
  • @Kusalananda it is running /bin/sh and there's no ~/.bashrc nor is there any other file (also no .files) in the home directory. – stdcerr Dec 13 '19 at 22:12
1

As last resort you can maybe use the program "expect".

Here is a simple example how to use expect with ssh: https://www.journaldev.com/1405/expect-script-ssh-example-tutorial

|improve this answer|||||
0

I just chatted with the guy that implemented this recently! He said it's due to the fact that the shell gets funneled through some other login binary for security reasons (ability to disable root access for production builds). The solution is to change the path to the extra binary in /etc/passwd back to the shell binary.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.