Skip to content

Instantly share code, notes, and snippets.

@laroo
Last active June 29, 2023 09:58
Show Gist options
  • Save laroo/5d7e62766d104119468a2ffe8678086b to your computer and use it in GitHub Desktop.
Save laroo/5d7e62766d104119468a2ffe8678086b to your computer and use it in GitHub Desktop.
Bash Blueprint - Simple
#!/usr/bin/env bash
function _trap_exit () {
echo "[exit]"
}
trap _trap_exit EXIT
function _trap_ctrl_c() {
echo "** Trapped CTRL-C"
exit -1
}
trap _trap_ctrl_c INT
IFS=$'\n\t'
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${SCRIPT_DIR}"
# -----------------------------------------------
echo "[start]"
export MY_VAR=testig
# ---------------------
# Date range loop
date_start=2016-01-01
while [[ "$date_start" < "2016-11-01" ]]; do
date_end=$(date -I -d "$date_start + 3 day")
echo "${date_start} - ${date_end}"
# python your_command $date_start $date_end
date_start=$(date -I -d "$date_start + 4 day")
done
# ---------------------
# Iterate file with ID's and batch per 50 to comma seperated string
while mapfile -t -n 50 ary && ((${#ary[@]})); do
ids=$(echo "${ary[@]}" | sed -z 's/ /,/g;s/,$/\n/')
echo $ids
# python your_command $ids
printf -- '--- SNIP ---\n'
done < /tmp/newline_separeted_list_of_ids.txt
echo "[done]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment