#!/bin/bash USAGE="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;; esac done if [[ -z "$@" ]]; then echo $USAGE >&2 exit 1 fi shift $((OPTIND - 1))