Skip to content

Instantly share code, notes, and snippets.

@FilBot3
Last active September 7, 2020 16:09
Show Gist options
  • Select an option

  • Save FilBot3/e3eea8bb8f76b8ccadba56d8d6f32e84 to your computer and use it in GitHub Desktop.

Select an option

Save FilBot3/e3eea8bb8f76b8ccadba56d8d6f32e84 to your computer and use it in GitHub Desktop.
A sample logging function for Bash scripts. Useful for CI/CD.
#!/usr/bin/env bash
function exec_log {
# This function prints a time + date stamps for use in Shell Scripts that are
# used in CI/CD. This also allows the user to run the same commands locally
# as they can in CI/CD.
exec_date=$(date --rfc-3339=ns)
echo "[${exec_date}]: $*"
echo "[${exec_date}]: $(exec $*)"
}
exec_log echo 'Hello, World!'
exec_log cat sample_logging.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment