All pastes #257673 Raw Edit

Miscellany

public shellscript v1 · immutable
#257673 ·published 2006-11-25 17:14 UTC
rendered paste body
#!/bin/bashUSAGE="Usage: $0 [-h] -[ s confdir | c ]"function server {	progname="${0%\.*}"		#deal with the PID file	if [ -e "$progname.pid" ]; then		echo "$progname is already running." >&2		exit 1	else		echo $$ > "$progname.pid"	fi		#bring values from conffile into current context	#eval `cat $1/$progname.conf`	eval `cat $progname.conf`			#ok here it's time to trap signals	#trap "eval `cat $progname.conf` > $TTY" 1	trap "touch temp" 2	trap "echo $( pwd ) > $TTY" 30	trap "" 31		while true; do		sleep 1;	done}while getopts "hs:c" opt; do	case $opt in		s) #servertime			if [ -t 0 ]; then				export TTY=$(tty)				exec $0 $@ <&- >&- &			else				server $OPTARG			fi			printf "";;		c) #clienttime			client;;		h|*) echo $USAGE >&2; exit 1;;	esacdoneif [[ -z "$@" ]]; then	echo $USAGE >&2	exit 1fishift $((OPTIND - 1))