Skip to content

Instantly share code, notes, and snippets.

@craigvantonder
Created March 12, 2020 00:00
Show Gist options
  • Save craigvantonder/e8a071694ea94a2958cbb056657eb261 to your computer and use it in GitHub Desktop.
Save craigvantonder/e8a071694ea94a2958cbb056657eb261 to your computer and use it in GitHub Desktop.
Two ways to check if a SSH control socket is open in BASH
#!/bin/bash
# How can I fully log all bash scripts actions?
# https://serverfault.com/a/103569/210437
if test -S "/absolute/path/to/ssh_control_socket"; then
echo 'It exists'
fi
# Why can't bash recognize the existence of a socket file
# https://stackoverflow.com/a/37618542/2110294
TEST=`ssh -o ControlPath=ssh_control_socket -O check anything_but_required`
if [ "$TEST" = *"Master running"* ]; then
echo 'It exists'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment