Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ################################################################################
- ########## ShellWorldClock - stuff the world does not need
- ########## by default shows a list of date outputs according to
- ########## different timezones..... .. you can specify the list of zones as
- ########## parameters to it ... the first one should probably your local one. ;)
- ##########
- ##########
- ########## 2018-01-12 by hackbyte, do whatever you want with it. ;)
- ########## 2018-01-21 by hackbyte, little bit of cleanup and inline documentation ;)
- ########## 2018-01-21 by hackbyte, added Pacific/Auckland (it's Rocket Labs launchpad in new zealand)
- ########## 2018-07-07 by hackbyte, removed mysteriously disappeared %q, shortened output anyway. You can reverse it as you ########## like......
- ################################################################################
- # getting the actual time and date to have consistent conversion times later
- THISDATE=$(LC_TIME=C date --utc)
- # Were using these timezones, put your local timezone as first one! ;)
- TIMEZONES="Europe/Berlin Universal America/Cayenne US/Central US/Eastern EST US/Pacific Asia/Almaty Asia/Kolkata Asia/Tokyo Pacific/Auckland"
- # we show this output for each timezone
- # default up to 2018-07-07 ## somehow %q disappeared and well, the rest was unnecessary anyways.. 8)
- # DATEFORMAT="%_4Z %_3::z %F %T (%B %A Q:%q W:%U D:%j)"
- # Shortened variant:
- DATEFORMAT="%_4Z %_3::z %F %T (%B %A)"
- # The first timezone in the list is per definition our local timezone ;)
- LOCALTZ=$(echo $TIMEZONES | awk '{print $1}')
- ################################################################################
- ########## Anything you can configure is above, usually no one needs to
- ########## do any maintenance below ...
- ##########
- ########## in other words, no user serviceable parts below
- ##########
- ########## eniweh, feel free to hack as you like... ;)
- ################################################################################
- ################################################################################
- # This just repeatedly calls date with the timezone setting in the list for/with each entry
- function displayclocks {
- while [ -n "$*" ] ; do # As long as $1 is not empty/zero
- printf "%17s" $1
- TZ="$1" date --date="$THISDATE" +"$DATEFORMAT" # set TZ to the correct value and then call date
- if [ "$1" = "$LOCALTZ" ] ; then echo ; fi # if we are at the local timezione, just print an empty line
- shift # remove the first parameter from the list, shorting it down by one
- done # and repeat ;)
- }
- ################################################################################
- ## here we go with the main functionality
- if [ -z "$*" ] ; then # if we have no cmdline parameters
- displayclocks $TIMEZONES # call displayclocks with our internal default list
- exit # and out
- else # or
- TIMEZONES="" # empty the timezones variable
- while [ -n "$1" ] ; do # while we have more parameters
- TIMEZONES="${TIMEZONES} ${1}" #> append the actual value to the variable with a trailing space
- shift # shift the parameter list once
- done # and repeat
- displayclocks $TIMEZONES # finally, call the displayclocks with the new list
- fi
- exit # Houston! Mission accomplished. ;)
Add Comment
Please, Sign In to add comment