Add example-gemini-awk.sh

This commit is contained in:
styan 2020-05-24 02:08:00 +00:00
parent 28fe4e659f
commit f4eea4e8d0
1 changed files with 23 additions and 0 deletions

23
example-gemini-awk.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/sh
HOST="${HOST:-localhost}"
PORT="${PORT:-1965}"
while getopts h:p: opt; do
case "$opt" in
h) HOST="$OPTARG";;
p) PORT="$OPTARG";;
*) usage;;
esac
done
shift $((OPTIND - 1))
for x in "$@"; do
fdwrap -f '3>stdin,stdin<stdout' -w \
"openssl s_client -quiet -connect $HOST:$PORT 2>/dev/null" \
awk 'BEGIN {
u = ARGV[1];
ARGV[1] = "-"
gsub(/'\''/, "&\\&&", u)
system("printf %s\\\\r\\\\n '\''" u "'\''>&3")
while (getline)
print
}' "$x"
done