#!/bin/bash #rktime: A utility to show the time in different places. #author: Richard Keech, Red Hat Asia-Pacific, rkeech@redhat.com #copyright (c) G.Richard Keech. #This program is released under the terms of the GNU General Public #License, version 2. LANG=C #================================================================= # Shell function showtime () formats time for a single timezone. showtime () { ZONE=$1 olddate=$date date=$(TZ=$ZONE /bin/date --date="$rt" --iso=date) if [ "${TIMEFORMAT}x" = "12hx" ] then time=$(TZ=$ZONE /bin/date --date="$rt" "+%_l:%M %p") else time=$(TZ=$ZONE /bin/date --date="$rt" +%H:%M) fi offset=$(TZ=$ZONE /bin/date --date="$rt" +%z) if [ "${TIMEOFFSET}x" = "onx" ] then time="$time $offset" fi day=$(TZ=$ZONE /bin/date --date="$rt" +%a) hour=$(TZ=$ZONE /bin/date --date="$rt" +%H) aZONE=$(TZ=$ZONE /bin/date --date="$rt" +%Z) oZONE=$ZONE if [ "${ZONE}x" = "UTCx" ] then ZONE=${YELLOW}${ZONE}${RC} fi if [ ${localoffset}x = ${offset}x ] then ZONE="${ZONE} ${RED}<-${RC}" fi case $day in Mon|Tue|Wed|Thu|Fri) weekday=true;; *) weekday=false;; esac if [ $hour -ge 8 -a $hour -le 18 ] then workhour=true else workhour=false fi if [ "${olddate}x" != "${date}x" -a "${olddate}x" != x ] then echo ------------------new day---------------------- fi if [ "${ZONE}x" != "${oZONE}x" ] then UZONE=$ZONE else UZONE="$(printf "%-20s %5s" $ZONE $aZONE)" fi if [ $workhour = true -a $weekday = true ] then echo "$date ${WEEKDAY_COLOR}$time $day ${RC}$UZONE" else if [ $weekday = true ] then # after hours echo "$date ${AFTERHOURS_COLOR}$time $day ${RC}$UZONE" else #weekend echo "$date ${WEEKEND_COLOR}$time $day ${RC}$UZONE" fi fi } # End of showtime () #-------------------------------------------------------------------------- # Check that file has appropriate security. checkfile () { if [ ! -f "${1}" ] then echo "File \"${1}\" does not exist or is not in the expected location." return 1 fi lsout="$(ls -l $1 2> /dev/null)" othermodes=$(echo $lsout|awk '{print $1}'|cut -c8-10) owner=$(echo $lsout|awk '{print $3}') group=$(echo $lsout|awk '{print $4}') if [ "${othermodes}z" != "r--z" -a "${othermodes}z" != "---z" ] then error For security, file $1 must only be \ writable and executable \(where appropriate\) by owner and group. fi if [ "${owner}x" != rootx -a "${owner}x" != binx ] then error For security, file $1 must be owned by only root or bin. fi if [ "${group}x" != rootx -a "${group}x" != binx ] then error For security, file $1 must be associated only with \ group root or bin. fi } # checkfile () #-------------------------------------------------------------------------- help () { PROG=$(basename $0) cat <