Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 67 lines (54 sloc) 1.18 KB
#!/bin/sh
#
# Show the age in seconds of a running or completed command which
# was run under the age-track wrapper. exit 0 if still running, 1 otherwise.
AGE_DIR="$HOME/.age"
me=`basename $0`
usage () {
cat <<EOF >&2
Usage: $me [-n] COMMAND [ARGS]
-n Calculate age as if process was still running
EOF
exit 1
}
if [ "$1" == -h ] || [ "$1" == --help ] || [ $# -eq 0 ]; then
usage
fi
if [ "$1" = -n ]; then
now=y
shift
fi
cmd="$1"
shift
base_cmd=`basename "$cmd"`
cmd_dir="$AGE_DIR/$base_cmd"
start_file="$cmd_dir/start"
end_file="$cmd_dir/end"
if ! [ -d "$cmd_dir" ]; then
echo "$cmd_dir does not exist; was the command run under age-track?" >&2
exit 1
fi
if ! [ -e "$start_file" ]; then
echo "$start_file does not exist; aborting." >&2
exit 1
fi
start=$( cat "$start_file" )
if [ -e "$end_file" ]; then
end=$( cat "$end_file" )
exit=1 # command not running
if [ "$end" -lt "$start" ]; then
echo "Command still running." >&2
end=$( date +"%s" )
exit=0
fi
else
# no end file, must still be running
echo "Command still running." >&2
end=$( date +"%s" )
exit=0
fi
if [ -n "$now" ]; then
end=$( date +"%s" )
fi
echo $(( end - start ))
exit $exit
Something went wrong with that request. Please try again.