Skip to content

Instantly share code, notes, and snippets.

@robshep
Last active April 17, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robshep/54095e5ed9811d904ad441f460b08a08 to your computer and use it in GitHub Desktop.
Save robshep/54095e5ed9811d904ad441f460b08a08 to your computer and use it in GitHub Desktop.
Linux Shell Power Snippets

Snippets for the shell (mostly bash)

Fetch a URL when you don't have wget or curl (e.g in an alpine docker container)

# drop in a function
fetch() { (echo -ne "GET $2 HTTP/1.0\r\nHost: $1\n\r\n"; sleep 5) | \
           openssl s_client -connect $1:443 -quiet -msgfile /dev/null | \
           perl -pe 'BEGIN { while (<>) { last if $_ eq "\r\n"; } }';
}

# call the function, manually splitting host and uri and dropping scheme
fetch "raw.githubusercontent.com"  "/gabrielelana/mongodb-shell-extensions/master/released/mongorc.js" > /tmp/.mongorc.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment