Skip to content

Instantly share code, notes, and snippets.

@rockymadden
Last active October 30, 2018 00:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rockymadden/57eb647d09f8279fe6e9 to your computer and use it in GitHub Desktop.
Save rockymadden/57eb647d09f8279fe6e9 to your computer and use it in GitHub Desktop.
socat examples

Effectively tail a file and serve it up via a browser:

socat -T0.05 -u FILE:/var/log/syslog,ignoreeof TCP4-LISTEN:12345,fork,reuseaddr

Simple file server

socat TCP-LISTEN:8080,reuseaddr,fork,crlf SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo Connection\: close; echo; cat /Users/rockymadden/.socat"

Mirror filesystem:

Source:

dd if=/dev/sdb1 | socat - openssl:sinkhost:9999

Sink:

socat openssl-listen:9999 | dd of=/dev/sdc1

pg_dump without touching disk to another server:

Source:

pg_dump -C dbname | bzip2 | socat - openssl:sink:8443

Sink:

socat openssl-listen:8443 > dbname.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment