0

It seems that this question needs some explanations.

Current I wrote a ssh wrapper bash function that is starting or restoring tmux sessions on the remote hosts.

It's presence is totally transparent to the user, you just type ssh host and because function ssh() { ... } is defined inside your .bash_profile this will be executed instead of real ssh.

Now, I do have this problem, on a small percentage of hosts they do not have a real shell and they have a pseudo-shell that drops the ssh connection if it receives commands that it does not understand. Examples: NetScaler, Synology (uses ash), CISCO routers, ...

What I want to do is to embed some login inside the ssh() wrapper so it will stop failing on these machines. Initially I made a blacklist but this shortly became too hard to manage, I need a proper fix.

ssh host.example.com
X11 forwarding request failed on channel 0
ash: darwin: unknown operand
ash: md5sum: not found
ash: syntax error: 0x
Connection to host.example.com closed.

>$ echo $?
0

How can I solve this problem from inside the bash function?

pgl
  • 7,551
  • 2
  • 23
  • 31
sorin
  • 161,544
  • 178
  • 535
  • 806
  • you typed remove hosts twice, can be a typo? – PradyJord May 13 '14 at 11:27
  • Nope, the problem is that my ssh wrapper is trying to execute (a very log) command line on the remote host, and fails with `ash`. The solution would be to detect the failure and to retry in simple mode (without the command). – sorin May 13 '14 at 11:33
  • 1
    Your remote isn't running a "pseudo-shell", it's just running a POSIX-compliant shell that isn't `bash`. What is the remote command you are trying to execute? You should try to make that POSIX-compliant, so that it will work on any remote host (that has a POSIX-compliant shell, anyway). – chepner May 13 '14 at 11:50
  • It's impossible because there are lots of commands (is more like a script than a simple command, with IFs and so on..). ash will kill the connection on the 3rd command execution failure. But I think I do have a retry solution, I am testing it now, seems to work well with one server. As soon I have more confidence I will post the code. – sorin May 13 '14 at 11:56
  • Sounds like you're on the right path. I'm torn between voting to close as too broad, and posting an answer which says "Write POSIX-compatible code". Neither seems right :) Consider posting new questions for any issues you have with writing code that is free from bashisms and other non-POSIX constructs. – chepner May 13 '14 at 13:28
  • At the risk of pointing the obvious, in your function, can't you make the first few lines to detect the shell and abort execution if not bash (or switch to basic command set as you have said) ? Such as `"env | grep SHELL |grep bash; r=$?"` and `if [ $r -ne 0 ];then; echo "switch to basic commands here"` – MelBurslan May 13 '14 at 16:08
  • I will post my entire example, if anyone can provide POSIX fixes to it, I will be more than happy to use them. – sorin May 13 '14 at 17:21

0 Answers0