Skip to content

Instantly share code, notes, and snippets.

@davidoram
Created May 22, 2018 03:43
Show Gist options
  • Select an option

  • Save davidoram/4995f6769b8a5f930ea9613fe4b65d20 to your computer and use it in GitHub Desktop.

Select an option

Save davidoram/4995f6769b8a5f930ea9613fe4b65d20 to your computer and use it in GitHub Desktop.

Revisions

  1. davidoram created this gist May 22, 2018.
    23 changes: 23 additions & 0 deletions unix-socket-to-tcp.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash

    set -e

    if [ $# -ne 3 ]; then
    echo "Usage:"
    echo ""
    echo " `basename $0` <unix socket file> <host> <listen port>"
    echo ""
    echo "For example:"
    echo ""
    echo " `basename $0` /tmp/.s.PGSQL.5432 localhost 5432"
    echo ""
    echo "Will create a Unix socket at '/tmp/.s.PGSQL.5432' and connect it to TCP socket on 'localhost:5432'"
    echo ""
    exit
    fi

    SOCK=$1
    HOST=$2
    PORT=$3

    socat -d -d -d -lf ${HOME}/tmp/socat.log UNIX-LISTEN:${SOCK},reuseaddr,fork TCP:${HOST}:${PORT}