Skip to main content
added "exec" keyword, and added note about executing more commands than `echo "Fail!"`. Forgot quotes
Source Link
Alex Stragies
  • 6.2k
  • 2
  • 35
  • 58

You could start with:

socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && exec nc 127.0.0.1 22 || echo Failed'"Fail!"'

So, Instead of tcp:127.0.0.1:12345 you spawn a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds (exec)
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

For the Optional part, just replace 'echo "Fail!" from above with

{ echo "SomeMsg; MoreCommands; }

I can help, if you need help adapting this, just update your Q with info where you got stuck

You could start with:

socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && nc 127.0.0.1 22 || echo Failed'

So, Instead of tcp:127.0.0.1:12345 you spawn a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds (exec)
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

I can help, if you need help adapting this, just update your Q with info where you got stuck

You could start with:

socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && exec nc 127.0.0.1 22 || echo "Fail!"'

So, Instead of tcp:127.0.0.1:12345 you spawn a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds (exec)
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

For the Optional part, just replace 'echo "Fail!" from above with

{ echo "SomeMsg; MoreCommands; }

I can help, if you need help adapting this, just update your Q with info where you got stuck

added concrete example
Source Link
Alex Stragies
  • 6.2k
  • 2
  • 35
  • 58

You could start with:

socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && nc 127.0.0.1 22 || echo Failed'

So, Instead of tcp:127.0.0.1:12345 you could try spawningspawn a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds (exec)
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

Something starting from here might help on your quest:

{ nc -z 127.0.0.1 12345 </dev/null 2>/dev/null \
  && exec nc 127.0.0.1 12345 } \
|| echo "Service @ 12345 not responding, try again later"

I can help, if you need help adapting this, just update your Q with info where you got stuck

Instead of tcp:127.0.0.1:12345 you could try spawning a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

Something starting from here might help on your quest:

{ nc -z 127.0.0.1 12345 </dev/null 2>/dev/null \
  && exec nc 127.0.0.1 12345 } \
|| echo "Service @ 12345 not responding, try again later"

I can help, if you need help adapting this, just update your Q with info where you got stuck

You could start with:

socat tcp-l:8080,fork,reuseaddr \
SYSTEM:'nc -z 127.0.0.1 22 >/dev/null && nc 127.0.0.1 22 || echo Failed'

So, Instead of tcp:127.0.0.1:12345 you spawn a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds (exec)
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

I can help, if you need help adapting this, just update your Q with info where you got stuck

Source Link
Alex Stragies
  • 6.2k
  • 2
  • 35
  • 58

Instead of tcp:127.0.0.1:12345 you could try spawning a shell_fragment/script, that more-or-less:

Check, if 127.0.0.1 12345 responds
  if yes, connect there and pass over the fds
  if no, echo "Service@12345 is down"
    Optional: don't exit, but enter a while loop
      Try reaching port 12345, then connect eventually

Something starting from here might help on your quest:

{ nc -z 127.0.0.1 12345 </dev/null 2>/dev/null \
  && exec nc 127.0.0.1 12345 } \
|| echo "Service @ 12345 not responding, try again later"

I can help, if you need help adapting this, just update your Q with info where you got stuck