#!/bin/ash # # ip2cn-server client2 with listen check # # get .conf port port=$(/usr/bin/gawk '/^inetport/ {print $2}' /etc/ip2cn-server.conf) # perhaps replace with optional port number from command line [ -n "$2" ] && port=$2 # check if server listening on this port, exit if not [ $(netstat -l | grep $port | grep -c LISTEN) -eq 0 ] && echo " No server on port $port, exit " && exit 1 # submit query + port to server echo $1 | /usr/bin/gawk -v port=$port ' BEGIN { service = "/inet/tcp/0/localhost/" port } { print |& service service |& getline print }'