-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feature/sc tail #208
Open
ajshedivy
wants to merge
4
commits into
ThePrez:main
Choose a base branch
from
ajshedivy:feature/sc-tail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/sc tail #208
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/QOpenSys/pkgs/bin/bash | ||
|
||
if [[ "$LC_ALL" != *UTF-8* ]]; then | ||
# LC_ALL is not set. Set it to EN_US.UTF-8 if present | ||
if [ -e /usr/lib/nls/loc/EN_US.UTF-8 ]; then | ||
export LC_ALL=EN_US.UTF-8 | ||
else | ||
# EN_US.UTF-8 is not present. Look for installed UTF-8 locale | ||
INSTALLEDUTF8LOCALE=$(ls -b /usr/lib/nls/loc | grep -E '.UTF-8$' | tail -n 1) | ||
if [[ "" = "$INSTALLEDUTF8LOCALE" ]]; then | ||
>&2 echo "WARNING: Cannot find a UTF-8 locale installed on this system." | ||
else | ||
export LC_ALL=$INSTALLEDUTF8LOCALE | ||
fi | ||
fi | ||
fi | ||
|
||
if (($# == 0)); then | ||
echo "usage: sctail [tail OPTION]... <service name>" | ||
exit 0 | ||
fi | ||
|
||
HELP_MSG=NO | ||
|
||
# Set the default arguments for tail | ||
TAIL_ARGS="" | ||
|
||
# Initialize variable for service name | ||
SERVICE="" | ||
|
||
# Declare an array to hold the arguments and their values | ||
declare -a ARGS=() | ||
|
||
# Loop through the command line arguments | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
-c|--bytes|-n|--lines|-s|--sleep-interval|--pid|--max-unchanged-stats) | ||
# If the argument has a value, add it to the array | ||
if [[ $# -gt 1 && "$2" != -* ]]; then | ||
ARGS+=("$1 $2") | ||
shift | ||
else | ||
ARGS+=("$1") | ||
fi | ||
;; | ||
-f|--follow|-F|--retry|-q|--quiet|--silent|-v|--verbose|-z|--zero-terminated|--version) | ||
ARGS+=("$1") | ||
;; | ||
--help) | ||
HELP_MSG=YES | ||
shift # past argument with no value | ||
;; | ||
-*|--*) | ||
echo "sctail: invalid option -- '$1'" | ||
echo "usage: sctail [OPTION]... <service name>" | ||
echo "Try 'sctail --help' for more information." | ||
exit 1 | ||
;; | ||
*) | ||
|
||
# If the argument doesn't start with a dash, set it as the SERVICE value | ||
SERVICE="$1" | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [[ $HELP_MSG == YES ]]; then | ||
echo "sctail usage: sctail [tail OPTION]... <service name]" | ||
exec /QOpenSys/pkgs/bin/tail --help | ||
exit 0 | ||
fi | ||
|
||
|
||
if [[ ${#ARGS[@]} -gt 0 ]]; then | ||
TAIL_ARGS+=" ${ARGS[*]}" | ||
fi | ||
|
||
|
||
echo "SERVICE: $SERVICE" | ||
echo "TAIL_ARGS: $TAIL_ARGS" | ||
|
||
LOG=$($(dirname $0)/sc loginfo $SERVICE | /QOpenSys/pkgs/bin/cut -d ':' -f 2 | awk '{ for (i=1; i<=NF; i++) print $i }') | ||
if [[ -z $LOG ]]; then | ||
echo "No log file found for service $SERVICE" | ||
exit 1 | ||
fi | ||
|
||
echo "LOG: $LOG" | ||
|
||
exec /QOpenSys/pkgs/bin/tail $TAIL_ARGS $LOG | ||
ajshedivy marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took another look at the mainline sc code and realize we need to account for the case where
sc loginfo
provides one or more spooled filesServiceCommander-IBMi/src/main/java/jesseg/ibmi/opensource/OperationExecutor.java
Line 614 in 7917211
As far as I know, there's no already-made utility for displaying spooled files in a terminal, and definitely nothing analagous to
tail -f
. Some ideas:db2util
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the QSHELL catsplf command, which can be run from PASE environment like this:
qsh -c "catsplf -j 123456/USER/JOB <spoolfilename> <spoolfilenumber>"
But I don't know if it's to cumbersome?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrjorgensen, cool! I think we should use that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to add support for "tailing" spool files. What would be the best way to configure a service that creates spool files to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found splf documentation 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By design, I can only view the spool file if the service has stopped (per quickstart demo). If I call
catsplf
on a running service I get the following output:but once the service is stopped, I can no longer view the
DSPSPLF
command fromloginfo
.sctail
works great on running services, since we can access the log file via existingsc
commands. In the spool file case, we would need to track the qualified job of the service which would require changing the sc base code unless there is another way to get that service informationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajshedivy Spool files have (and always have had) the problem that the output is written in blocks and the latest output can not be seen until that block has finished and another block is created. Your problem is the same as when the `DSPSPLF´ command is used - or when the SYSTOOLS.SPOOLED_FILE_DATA() is used.
This makes spool files unsuitable for logs IMHO... writing to streamfiles is much better!
@ThePrez Do you know if it's possible to redirect spool output to a streamfile, while the spool file is open? If not, then I don't think a
tail
option for spool files can be done...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrjorgensen I don't think so, while the splf is still open :(