2 # Desc: A list of executables to be started every day at midnight.
3 # Usage: nfg_run_daily_jobs.sh arg1
4 # Input: arg1: path to directory containing ninfacyzga-1 repository
6 # Note: These jobs permit the general strategy of storing current instances of
7 # observed data in a temporary directory that can be accessed as a file from
8 # other scripts without each script having to know about eachother's
10 # Note: Run this script daily at midnight using `cron`.
12 #==BEGIN Define script parameters==
14 nfg_exec_dir
="$nfg_base_dir"/exec;
15 length_day_s
=$
((24 * 60 * 60)); # seconds
17 #===BEGIN Define variables===
18 declare -Ag appRollCall
# Associative array for storing app status
19 declare -Ag fileRollCall
# Associative array for storing file status
20 declare -Ag dirRollCall
# Associative array for storing dir status
21 #===END Define variables===
22 #===BEGIN Declare local script functions===
23 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
24 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
25 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
27 # Desc: If arg is a command, save result in assoc array 'appRollCall'
28 # Usage: checkapp arg1 arg2 arg3 ...
30 # Input: global assoc. array 'appRollCall'
31 # Output: adds/updates key(value) to global assoc array 'appRollCall'
37 if command -v "$arg" 1>/dev
/null
2>&1; then # Check if arg is a valid command
38 appRollCall
[$arg]="true";
39 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi;
41 appRollCall
[$arg]="false"; returnState
="false";
45 #===Determine function return code===
46 if [ "$returnState" = "true" ]; then
51 } # Check that app exists
53 # Desc: If arg is a file path, save result in assoc array 'fileRollCall'
54 # Usage: checkfile arg1 arg2 arg3 ...
56 # Input: global assoc. array 'fileRollCall'
57 # Output: adds/updates key(value) to global assoc array 'fileRollCall';
58 # Output: returns 0 if app found, 1 otherwise
64 if [ -f "$arg" ]; then
65 fileRollCall
["$arg"]="true";
66 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi;
68 fileRollCall
["$arg"]="false"; returnState
="false";
72 #===Determine function return code===
73 if [ "$returnState" = "true" ]; then
78 } # Check that file exists
80 # Desc: If arg is a dir path, save result in assoc array 'dirRollCall'
81 # Usage: checkdir arg1 arg2 arg3 ...
83 # Input: global assoc. array 'dirRollCall'
84 # Output: adds/updates key(value) to global assoc array 'dirRollCall';
85 # Output: returns 0 if app found, 1 otherwise
91 if [ -d "$arg" ]; then
92 dirRollCall
["$arg"]="true";
93 if ! [ "$returnState" = "false" ]; then returnState
="true"; fi
95 dirRollCall
["$arg"]="false"; returnState
="false";
99 #===Determine function return code===
100 if [ "$returnState" = "true" ]; then
105 } # Check that dir exists
107 # Desc: Displays missing apps, files, and dirs
108 # Usage: displayMissing
110 # Input: associative arrays: appRollCall, fileRollCall, dirRollCall
111 # Output: stderr: messages indicating missing apps, file, or dirs
112 # Depends: bash 5, checkAppFileDir()
113 local missingApps value appMissing missingFiles fileMissing
114 local missingDirs dirMissing
116 #==BEGIN Display errors==
117 #===BEGIN Display Missing Apps===
118 missingApps
="Missing apps :";
119 #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done
120 for key
in "${!appRollCall[@]}"; do
121 value
="${appRollCall[$key]}";
122 if [ "$value" = "false" ]; then
123 #echo "DEBUG:Missing apps: $key => $value";
124 missingApps
="$missingApps""$key ";
128 if [ "$appMissing" = "true" ]; then # Only indicate if an app is missing.
129 echo "$missingApps" 1>&2;
132 #===END Display Missing Apps===
134 #===BEGIN Display Missing Files===
135 missingFiles
="Missing files:";
136 #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done
137 for key
in "${!fileRollCall[@]}"; do
138 value
="${fileRollCall[$key]}";
139 if [ "$value" = "false" ]; then
140 #echo "DEBUG:Missing files: $key => $value";
141 missingFiles
="$missingFiles""$key ";
145 if [ "$fileMissing" = "true" ]; then # Only indicate if an app is missing.
146 echo "$missingFiles" 1>&2;
149 #===END Display Missing Files===
151 #===BEGIN Display Missing Directories===
152 missingDirs
="Missing dirs:";
153 #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done
154 for key
in "${!dirRollCall[@]}"; do
155 value
="${dirRollCall[$key]}";
156 if [ "$value" = "false" ]; then
157 #echo "DEBUG:Missing dirs: $key => $value";
158 missingDirs
="$missingDirs""$key ";
162 if [ "$dirMissing" = "true" ]; then # Only indicate if an dir is missing.
163 echo "$missingDirs" 1>&2;
166 #===END Display Missing Directories===
168 #==END Display errors==
169 } # Display missing apps, files, dirs
171 # Note: Use '&' to run scripts and immediately detach them.
180 photo_script_path
="$nfg_exec_dir"/update_temp_photograph.sh
;
181 if checkfile
"$photo_script_path"; then
182 timeout
"$length_day_s"s
/bin
/bash
"$photo_script_path" &
184 yell
"ERROR:Not found:$photo_script_path";
189 #===END Declare local script functions===
190 #==END Define script parameters==