3 ms·
OK, I'll bite... The author would complain about my python3 in the same way and conclude it would be better to write it in my Bash. Without questioning the "wh
by adityaathalye 5y ago
OK, I'll bite... The author would complain about my python3 in the same way and conclude it would be better to write it in my Bash.
Without questioning the "why" of the script, sans my customary morning coffee, and without having tested the code below.
Maybe I'd do something like this.
For the small price of function invocation overhead, the nice benefit of doing it this way is that one can `source` the functions into one's Bash shell and use each one as a standalone Unix tool, complete with tabtab completion, pipelines etc.
#!/usr/bin/env bash
stop_app() {
pkill ${1:?Fail. App name required.}
}
today() {
date +%Y%m%d
}
analyse() {
local analyser=${1:?Fail. Analyser script name required.}
local out_dir=$(printf "results_%s" $(today))
while yaml_file
do local out_file="${out_dir}/summary_$(basename yaml_file).txt"
python3 ${analyser} ${yaml_file} > ${out_file}
printf "%s\n" ${out_file}
done
}
exec_analytics() {
local analyser=${1:?Fail. Analyser script name required.}
local source_dir=${2:-"~/Documents/ExtFin-EFS/smoke/"}
find ${source_dir} -type f -name *.yaml |
sort -r |
analyse ${analyser} |
tail -1
}
update_current() {
local latest_outfile=${1:?Fail. Provide latest output file.}
ln -sf ${latest_outfile} "current.txt"
}
And maybe one can invoke it like...
stop_app "whatever_app" && (
trap "rm -f /tmp/module_design_analytics_outfile" 0 HUP TERM PIPE INT
if exec_analytics module_design_analytics.py |
tail -1 > /tmp/module_design_analytics_outfile
then update_current $(printf /tmp/module_design_analytics_outfile)
echo "Done"
else echo "Oops. Something went wrong."
fi
trap - 0 HUP TERM PIPE INT
)