git://git.nikiroo.be
/
gofetch.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f81d83d
)
Update gopher.sh mini test service
author
Niki Roo
<niki@nikiroo.be>
Tue, 22 Aug 2017 19:54:47 +0000
(21:54 +0200)
committer
Niki Roo
<niki@nikiroo.be>
Tue, 22 Aug 2017 19:54:47 +0000
(21:54 +0200)
gopher.sh
[changed mode: 0644->0755]
patch
|
blob
|
blame
|
history
diff --git
a/gopher.sh
b/gopher.sh
old mode 100644
(file)
new mode 100755
(executable)
index
d0c9ea5
..
49e9caa
--- a/
gopher.sh
+++ b/
gopher.sh
@@
-1,19
+1,28
@@
-#!/bin/sh
+#!/bin/
ba
sh
-# $0 [prog ($1 will be the query)] ([port])
+# Note: bash is required, sh will fail to output anything to the client
+# Probably related to interactions beteween & and output redirections
+
+# $0 [prog] ([port])
+# You can use the evironment variable $QUERY_STRING for the query
[ "$ADDR" = "" ] && ADDR=127.0.0.1
[ "$ADDR" = "" ] && ADDR=127.0.0.1
-[ "$LOG" = "" ] && LOG=/tmp/
log
.err
+[ "$LOG" = "" ] && LOG=/tmp/
gopher.service
.err
[ "$PIDF" = "" ] && PIDF="`mktemp`"
[ "$TIMEOUT" = "" ] && TIMEOUT=10
[ "$MAXCON" = "" ] && MAXCON=1024
[ "$PIDF" = "" ] && PIDF="`mktemp`"
[ "$TIMEOUT" = "" ] && TIMEOUT=10
[ "$MAXCON" = "" ] && MAXCON=1024
+
prog="$1"
port="$2"
[ "$port" = "" ] && port=70
if [ "$prog" = "" ]; then
rm "$PIDF"
prog="$1"
port="$2"
[ "$port" = "" ] && port=70
if [ "$prog" = "" ]; then
rm "$PIDF"
- echo "Syntax: $0 [prog (\$1 will be the query)] ([port])" >&2
+ echo "Syntax: $0 [prog] ([port])" >&2
+ echo ' You can use the evironment variable $QUERY_STRING for the query' >&2
+ echo ' The default port is 70' >&2
+ echo ' A filename will be displayed, you can delete it to stop the service' >&2
+ echo ' (with a grace time of $TIMEOUT seconds)' >&2
exit 1
fi
exit 1
fi
@@
-32,16
+41,12
@@
while [ -e "$PIDF" ]; do
i=`expr $i + 1`
[ $i -gt "$MAXCON" ] && i=1
fifo="$tmpd/fifo.$i"
i=`expr $i + 1`
[ $i -gt "$MAXCON" ] && i=1
fifo="$tmpd/fifo.$i"
- rm -f "$fifo"
+ rm -f "$fifo"
2>/dev/null
mkfifo "$fifo"
< "$fifo" nc -l -q0 -w"$TIMEOUT" "$ADDR" -p "$port" | (
read -r query
mkfifo "$fifo"
< "$fifo" nc -l -q0 -w"$TIMEOUT" "$ADDR" -p "$port" | (
read -r query
- query="`echo "$query" | cut -f2 -d' '`"
- (
- "$prog" "$query" 2>> "$LOG"
- rm "$fifo"
- )&
+ query="`echo "$query" | cut -f2 -d' ' | sed 's:[\r\n]::g'`"
+ QUERY_STRING="$query" "$prog" 2>> "$LOG" &
) > "$fifo"
done
) > "$fifo"
done
-rm -rf "$tmpd"
-
+rm -rf "$tmpd" 2>/dev/null