From 183da5e3054d4cbad1ddb9ce66a3024703b74b68 Mon Sep 17 00:00:00 2001 From: vahid-dan Date: Thu, 22 Feb 2024 14:39:06 -0500 Subject: [PATCH] Add EddyFlux Get Files Module --- gateways/base/utils.sh | 8 +++++ gateways/config-files/henrietta/config.yml | 10 ++++++ gateways/cron-jobs/non-root | 3 ++ gateways/eddyflux/eddyflux-get-files.sh | 39 ++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 gateways/eddyflux/eddyflux-get-files.sh diff --git a/gateways/base/utils.sh b/gateways/base/utils.sh index 33bb9b1..fd7b251 100755 --- a/gateways/base/utils.sh +++ b/gateways/base/utils.sh @@ -105,6 +105,14 @@ export lora_radio_ingress_policing_burst=$(yq e '.lora_radio.ingress_policing_bu export nebula_overlay_network_is_enabled=$(yq e '.nebula_overlay_network.is_enabled' $config_file) export nebula_overlay_network_log_file=$(yq e '.nebula_overlay_network.log_file' $config_file) +# EddyFlux Get Files +export eddyflux_get_files_is_enabled=$(yq e '.eddyflux_get_files.is_enabled' $config_file) +export eddyflux_get_files_log_file=$(yq e '.eddyflux_get_files.log_file' $config_file) +export eddyflux_get_files_ssh_user=$(yq e '.eddyflux_get_files.ssh_user' $config_file) +export eddyflux_get_files_ssh_host=$(yq e '.eddyflux_get_files.ssh_host' $config_file) +export eddyflux_get_files_source_path=$(yq e '.eddyflux_get_files.source_path' $config_file) +export eddyflux_get_files_destination_path=$(yq e '.eddyflux_get_files.destination_path' $config_file) + ########## DEFINE FUNCTIONS ########## # Check if module is is_enabled diff --git a/gateways/config-files/henrietta/config.yml b/gateways/config-files/henrietta/config.yml index d253c25..1d52454 100644 --- a/gateways/config-files/henrietta/config.yml +++ b/gateways/config-files/henrietta/config.yml @@ -34,6 +34,7 @@ git_push: directories: - /data/fcre-catwalk-data - /data/henrietta-logs + - /data/fcre-eddyflux-data git_garbage_collector: is_enabled: true @@ -41,6 +42,7 @@ git_garbage_collector: directories: - /data/fcre-catwalk-data - /data/henrietta-logs + - /data/fcre-eddyflux-data health_checks_io: is_enabled: true @@ -104,3 +106,11 @@ lora_radio: nebula_overlay_network: is_enabled: true log_file: nebula-overlay-network.log + +eddyflux_get_files: + is_enabled: true + log_file: eddyflux-get-files.log + ssh_user: licor + ssh_host: 10.10.1.4 + source_path: ~/data/summaries/* + destination_path: /data/fcre-eddyflux-data/ diff --git a/gateways/cron-jobs/non-root b/gateways/cron-jobs/non-root index 75150ea..258a659 100644 --- a/gateways/cron-jobs/non-root +++ b/gateways/cron-jobs/non-root @@ -31,3 +31,6 @@ # Runs LoRa Radio @reboot sleep 60 && /home/ubuntu/miscellaneous/gateways/remote-access/lora-radio.sh 00 * * * * /home/ubuntu/miscellaneous/gateways/remote-access/lora-radio.sh + +# Gets EddyFlux Files +45 23 * * * /home/ubuntu/miscellaneous/gateways/eddyflux/eddyflux-get-files.sh diff --git a/gateways/eddyflux/eddyflux-get-files.sh b/gateways/eddyflux/eddyflux-get-files.sh new file mode 100644 index 0000000..cf571f1 --- /dev/null +++ b/gateways/eddyflux/eddyflux-get-files.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# EddyFlux Get Files Module +# This module downloads EddyFlux files to the gateway. +# Usage: Run periodically, every day, for instance. + +# SSH Access Sample Command: +# ssh -o PubkeyAcceptedAlgorithms=+ssh-rsa -oHostKeyAlgorithms=+ssh-rsa,ssh-dss licor@10.10.1.4 + +# SCP File Transfer Sample Command: +# scp -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostKeyAlgorithms=+ssh-rsa,ssh-dss -r licor@10.10.1.4:data/summaries/* /data/fcre-eddyflux-data/ + +########## HEADER ########## + +module_name=eddyflux_get_files + +# Load utility functions and configurations for gateways +source /home/ubuntu/miscellaneous/gateways/base/utils.sh + +# Check if the module is enabled +check_if_enabled "$module_name" + +# Redirect all output of this module to log_to_file function +exec > >(while IFS= read -r line; do log_to_file "$module_name" "$line"; echo "$line"; done) 2>&1 + +echo "########## START ##########" + +########## BODY ########## + +scp -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostKeyAlgorithms=+ssh-rsa,ssh-dss -r ${eddyflux_get_files_ssh_user}@${eddyflux_get_files_ssh_host}:${eddyflux_get_files_source_path} ${eddyflux_get_files_destination_path} + +########## FOOTER ########## + +echo "########## END ##########" + +# Close stdout and stderr +exec >&- 2>&- +# Wait for all background processes to complete +wait