Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure to show downstream command output #13

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions watcherd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MY_DATE="2022-12-17"
MY_URL="https://github.com/devilbox/watcherd"
MY_AUTHOR="cytopia <cytopia@everythingcli.org>"
MY_GPGKEY="0xA02C56F0"
MY_VERSION="1.0.3"
MY_VERSION="1.0.4"
MY_LICENSE="MIT"

# Default settings
Expand Down Expand Up @@ -130,17 +130,14 @@ function action() {
action="${action//%p/${directory}}"
action="${action//%n/${name}}"

if OUTPUT="$( eval "${action}" 2>&1 )"; then
if eval "${action}"; then
if [ "${verbose}" -gt "0" ]; then
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
fi
return 0
else
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}" >&2
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${action}" >&2
if [ -n "${OUTPUT}" ]; then
printf "%s: [%s] [ERR] %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${OUTPUT}" >&2
fi
return 1
fi
}
Expand All @@ -153,16 +150,13 @@ function trigger() {
# Only run trigger when command has been specified (not empty)
if [ -n "${action}" ]; then
if [ "${changes}" -eq "1" ]; then
if OUTPUT="$( eval "${action}" 2>&1 )"; then
if eval "${action}"; then
if [ "${verbose}" -gt "0" ]; then
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
fi
return 0
else
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}" >&2
if [ -n "${OUTPUT}" ]; then
printf "%s: [%s] [ERR] %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${OUTPUT}" >&2
fi
# Also return 0 here in order to not abort the loop
return 0
fi
Expand Down