Skip to content
Snippets Groups Projects

automation script for creating SCMI tiles using inotify

Merged Graeme Martin requested to merge graemem-nws into develop
1 file
+ 58
0
Compare changes
  • Side-by-side
  • Inline
bin/grb2scmi.sh 0 → 100755
+ 58
0
#!/bin/bash
#
# Example script demonstrating automation of SCMI tile generation using AXI-Tools.
#
# Requires inotify-tools (available as part of CentOS) be present.
# Requires these environment variables:
# GRB_PRODUCTS input L1B directory
# AXI_TOOLS AXI-Tools location
# SCENE ABI scene to filter on, e.g. RadC, RadM1, RadM2, RadF
# SCMI_REGION Region code to use in output SCMI filenames, e.g. ECONUS, EMESO1, EMESO2, EFD
# SCMI_ENV Environment and data type code to use in output SCMI filename, e.g. OT, OR, DT
#
# Invocation:
# /path/to/grb2scmi.sh
#
# Output is written to the working directory.
oops() {
echo "ERROR: $*"
exit 1
}
# configurable values provided in environment
test -d "$GRB_PRODUCTS" || oops "please set GRB_PRODUCTS environment to directory of arriving GRB products"
test -n "$AXI_TOOLS" || oops "Please set AXI_TOOLS in environment to indicate location of the AXI-Tools software"
test -x "$(which inotifywait)" || oops "inotify-tools is needed by this script."
export PY3=$AXI_TOOLS/ShellB3/bin/python3
test -x "$PY3" || oops "Could not find $PY3. Check environment variable AXI_TOOLS"
export CMI_CHANGER=$AXI_TOOLS/bin/cmi_changer.sh
test -f "$CMI_CHANGER" || oops "Could not find $CMI_CHANGER. Check environment variable AXI_TOOLS"test -n "$SCENE" || oops "please set SCENE in environment to indicate the scene to filter incoming files on (e.g. \"RadC\")" # e.g. "RadC" "RadM1", "RadM2", "RadF"
test -n "$SCMI_REGION" || oops "please set SCMI_REGION in environment to indicate the region to use in output files (e.g. \"ECONUS\")" # TCONUS, TMESO1, TMESO2, TFD for lack of a better guess
test -n "$SCMI_ENV" || oops "please set SCMI_ENV in environment to indicate the environment and data type to use in output files (e.g. \"OT\")" # OR, DT, etc
cmi_changer() {
# echo "+++ creating SCMI tiles using $*"
$CMI_CHANGER -E $SCMI_ENV -R $SCMI_REGION "$@"
}
export -f cmi_changer # needed when using with xargs and other forms of sub-shell like $(...)
# OR_ABI-L1b-RadM1-M3C
inotify_scene() {
scene="$1"
inotifywait -m -r -e close_write -e moved_to --format "${GRB_PRODUCTS}/%f" "$GRB_PRODUCTS" \
|grep --line-buffered -E ".*?_ABI-L1b-${scene}-M.*\.nc$"
}
inotify_main() {
inotify_scene $SCENE \
|xargs -P20 -L1 -I {} /bin/nice /bin/bash -c "cmi_changer {}"
}
while true; do
inotify_main &>${SCENE}-$(date '+%Y%m%dT%H%M%S').log || echo "ERROR: message loop exited"
echo "ERROR: timeout at $(date); restarting in 30s"
sleep 30
done
Loading