Skip to content

Instantly share code, notes, and snippets.

@yath
Last active August 29, 2015 14:11
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 yath/fa9267b7d399223fc77c to your computer and use it in GitHub Desktop.
Save yath/fa9267b7d399223fc77c to your computer and use it in GitHub Desktop.
sssh - sane(r) ssh
#!/bin/sh
# sssh - sane(r) ssh
#
# executes a remote command (more) sanely by passing the arguments url-like
# escaped (foo%23bar for "foo#bar") and unpacking them on the remote side
# with perl again.
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <host> <command> [arguments...]" >&2
exit 1
fi
host="$1"; shift
exec ssh "$host" "perl -le 's/%(..)/chr hex \$1/ge for @ARGV; exec { \$ARGV[0] } @ARGV or die \$!.\$/' --" \
$(perl -le 'for (@ARGV) { s/[^A-Za-z0-9,.-]/sprintf("%%%02x", ord $&)/ge; print }' -- "$@")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment