Skip to content

Commit

Permalink
Added --log-to-journal option hitachienergy#536
Browse files Browse the repository at this point in the history
  • Loading branch information
to-bar committed Oct 3, 2019
1 parent de1e836 commit 3ab5b62
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# VERSION 1.0.3
# VERSION 1.1.3

set -euo pipefail

Expand Down Expand Up @@ -108,7 +108,13 @@ download_packages() {
}

echol() {
echo -e "$1" |& tee --append $LOG_FILE_PATH
echo -e "$@"
if [[ $LOG_TO_JOURNAL = "YES" ]]; then
echo -e "$@" | systemd-cat --identifier=$SCRIPT_FILE_NAME
else # log to $LOG_FILE_PATH
local timestamp=$(date +"%b %e %H:%M:%S")
echo -e "${timestamp}: $@" >> "$LOG_FILE_PATH"
fi
}

# params: <repo_id>
Expand Down Expand Up @@ -269,6 +275,24 @@ usage() {

[ $# -gt 0 ] || usage 1 >&2

# --- Parse arguments ---

POSITIONAL_ARGS=()
LOG_TO_JOURNAL="NO"
while [[ $# -gt 0 ]]; do
case $1 in
--log-to-journal)
LOG_TO_JOURNAL="YES"
shift # past argument
;;
*) # unknown option
POSITIONAL_ARGS+=("$1") # save it in an array for later
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional arguments

# --- Global variables ---

# dirs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# VERSION 1.0.3
# VERSION 1.1.3

set -euo pipefail

Expand Down Expand Up @@ -108,7 +108,13 @@ download_packages() {
}

echol() {
echo -e "$1" |& tee --append $LOG_FILE_PATH
echo -e "$@"
if [[ $LOG_TO_JOURNAL = "YES" ]]; then
echo -e "$@" | systemd-cat --identifier=$SCRIPT_FILE_NAME
else # log to $LOG_FILE_PATH
local timestamp=$(date +"%b %e %H:%M:%S")
echo -e "${timestamp}: $@" >> "$LOG_FILE_PATH"
fi
}

# params: <repo_id>
Expand Down Expand Up @@ -286,6 +292,24 @@ usage() {

[ $# -gt 0 ] || usage 1 >&2

# --- Parse arguments ---

POSITIONAL_ARGS=()
LOG_TO_JOURNAL="NO"
while [[ $# -gt 0 ]]; do
case $1 in
--log-to-journal)
LOG_TO_JOURNAL="YES"
shift # past argument
;;
*) # unknown option
POSITIONAL_ARGS+=("$1") # save it in an array for later
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional arguments

# --- Global variables ---

# dirs
Expand Down

0 comments on commit 3ab5b62

Please sign in to comment.