#!/bin/bash # proj3.sh 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 source $progname.conf #ok here it's time to trap signals trap "echo $( pwd ) > $TTY" INT trap "echo $( pwd ) > $TTY" USR1 trap "" USR2 trap -p > $TTY 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))