3 # Author: Steven Baltakatei Sandoval
5 #== Variable Initialization ==
7 #== Global constants ==
8 PATH
="/usr/local/bin/:$PATH" # Add default OpenTimestamps path to PATH (necessary if cron used to call this script)
9 PATH
="/opt/bktei:$PATH" # Add default baltakatei script install directory to PATH (necessary for other bk scripts)
10 SCRIPT_HOSTNAME
=$
(hostname
) # Save hostname of system running this script.
11 SCRIPT_VERSION
="bkgpslog 0.0.1" # Define version of script.
12 SCRIPT_TIME_SHORT
="$(date +%Y%m%dT%H%M%S%z)" # Save current date & time in ISO-8601 format.
13 SCRIPT_DATE_SHORT
="$(date +%Y%m%d)" # Save current date in ISO-8601 format.
14 #DIROUT1="/home/pi/Sync/Evanescent_Location" # Define output directory.
16 #== Function Definitions ==
18 echo "$@" 1>&2; # Define stderr echo function.
19 } # Define stderr message function.
22 echoerr
" bkgpslog.sh [ options ]"
26 echoerr
" Display help information."
29 echoerr
" Display script version."
31 echoerr
" -v, --verbose"
32 echoerr
" Display debugging info."
34 echoerr
" -o, --output [ directory ]"
35 echoerr
" Specify output directory to save logs."
36 } # Display information on how to use this script.
38 echoerr
"$SCRIPT_VERSION"
39 } # Display script version.
41 if [ $OPTION_VERBOSE -eq "true" ]; then
44 } # Verbose message display function.
46 while [ ! $# -eq 0 ]; do # While number of arguments ($#) is not (!) equal to (-eq) zero (0).
47 echoerr
"DEBUG:Starting processArguments while loop."
48 echoerr
"DEBUG:Provided arguments are:""$@"
50 --h |
--help) showUsage
; exit 1;; # Display usage.
51 --version) showVersion
; exit 1;; # Show version
52 --v |
--verbose) OPTION_VERBOSE
="true"; vbm
"DEBUG:Verbose mode enabled.";; # Enable verbose mode.
53 --o |
--output) if [ -d "$2" ]; then DIROUT1
="$2"; fi ;; # Define output directory.
54 *) echoerr
"ERROR: Unrecognized argument."; exit 1;; # Handle unrecognized options.
58 } # Argument Processing
61 } # Check that certain executables exist.
64 processArguments
# Process arguments.
65 checkExecutables
"gpspipe" # Confirm that executables necessary to run are available.
73 if [[ -d "$DIROUT1" ]] && command -v "gpspipe" 1>/dev
/null
2>/dev
/null
; then
75 #echoerr "DEBUG:Starting while loop."
76 # Update time constants
77 TIME_CURRENT
="$(date --iso-8601=seconds)" ;
78 #echoerr "DEBUG:TIME_CURRENT is:""$TIME_CURRENT" ;
79 TIME_CURRENT_SHORT
="$(date -d "$TIME_CURRENT" +%Y%m%dT%H%M%S%z)"
80 #echoerr "DEBUG:TIME_CURRENT_SHORT is""$TIME_CURRENT_SHORT"
81 DATE_CURRENT
="$(date -d "$TIME_CURRENT" --iso-8601=date)" ;
82 #echoerr "DEBUG:DATE_CURRENT is:""$DATE_CURRENT" ;
83 DATE_CURRENT_SHORT
="$(date -d "$TIME_CURRENT" +%Y%m%d)" ;
84 #echoerr "DEBUG:DATE_CURRENT is:""$DATE_CURRENT_SHORT" ;
85 DATE_TOMORROW
="$(date -d "$TIME_CURRENT next day
" --iso-8601=date)" ;
86 #echoerr "DEBUG:DATE_TOMORROW is:""$DATE_TOMORROW" ;
87 TIME_NEXT_MIDNIGHT
="$(date -d "$DATE_TOMORROW" --iso-8601=seconds)" ;
88 #echoerr "DEBUG:TIME_NEXT_MIDNIGHT is:""$TIME_NEXT_MIDNIGHT" ;
89 SECONDS_UNTIL_NEXT_MIDNIGHT
="$(( $(date +%s -d "$TIME_NEXT_MIDNIGHT") - $(date +%s -d "$TIME_CURRENT") ))" ;
90 #echoerr "DEBUG:SECONDS_UNTIL_NEXT_MIDNIGHT is:""$SECONDS_UNTIL_NEXT_MIDNIGHT" ;
91 if [ "$SECONDS_UNTIL_NEXT_MIDNIGHT" -eq 0 ]; then echoerr
"WARNING:Is it exactly midnight?" ; continue; fi ; # Exit loop early if equal to 0 because "timeout 0s" never ends.
92 if [ "$SECONDS_UNTIL_NEXT_MIDNIGHT" -lt 0 ]; then echoerr
"ERROR:Time until midnight error." ; exit 1; fi ; # Exit script if equal to 0 because "timeout 0s" never ends.
94 # Update output file names.
96 FILEOUTN
="$DATE_CURRENT_SHORT""..""$(hostname)""_location.nmea" ;
98 # Append location log until midnight.
99 timeout
"$SECONDS_UNTIL_NEXT_MIDNIGHT""s" gpspipe
-r 1>> "$DIROUTN"/"$FILEOUTN" 2>>/dev
/null
; # log raw nmea data
102 #gpspipe -r -d -l -o "$DIROUT1"/"$FILEOUT1" ;
105 echo "$SCRIPT_TIME_SHORT"">gpspipe or $DIROUT1 not found." >> ~
/"$SCRIPT_DATE_SHORT"..error.log
;