-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
set -eux | ||
set -o pipefail | ||
|
||
SERVICE_NAME=invocation-id-test-"$RANDOM".service | ||
|
||
TMP_DIR=$(mktemp -d) | ||
|
||
for i in {1..10}; do | ||
systemd-run --wait -u "$SERVICE_NAME" bash -c "echo invocation ${i} \$INVOCATION_ID; journalctl --sync" | ||
done | ||
|
||
journalctl --list-invocation -u "$SERVICE_NAME" | tee "$TMP_DIR"/10 | ||
journalctl --list-invocation -u "$SERVICE_NAME" --reverse | tee "$TMP_DIR"/10-r | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n +10| tee "$TMP_DIR"/p10 | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n +10 --reverse | tee "$TMP_DIR"/p10-r | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n 5 | tee "$TMP_DIR"/5 | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n 5 --reverse | tee "$TMP_DIR"/5-r | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n +5 | tee "$TMP_DIR"/p5 | ||
journalctl --list-invocation -u "$SERVICE_NAME" -n +5 --reverse | tee "$TMP_DIR"/p5-r | ||
|
||
[[ $(cat "$TMP_DIR"/10 | wc -l) == 11 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/10-r | wc -l) == 11 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/p10 | wc -l) == 11 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/p10-r | wc -l) == 11 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/5 | wc -l) == 6 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/5-r | wc -l) == 6 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/p5 | wc -l) == 6 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
[[ $(cat "$TMP_DIR"/p5-r | wc -l) == 6 ]] | ||
Check warning Code scanning / shellcheck Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Warning
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
|
||
|
||
diff <(tail -n 10 "$TMP_DIR"/10 | tac) <(tail -n 10 "$TMP_DIR"/10-r) | ||
diff <(tail -n 5 "$TMP_DIR"/10) <(tail -n 5 "$TMP_DIR"/5) | ||
diff <(tail -n 5 "$TMP_DIR"/10 | tac) <(tail -n 5 "$TMP_DIR"/5-r) | ||
diff <(tail -n 10 "$TMP_DIR"/p10 | tac) <(tail -n 10 "$TMP_DIR"/p10-r) | ||
diff <(tail -n 10 "$TMP_DIR"/p10 | head -n 5) <(tail -n 5 "$TMP_DIR"/p5) | ||
diff <(tail -n 10 "$TMP_DIR"/p10 | head -n 5 | tac) <(tail -n 5 "$TMP_DIR"/p5-r) | ||
|
||
tail -n 10 "$TMP_DIR"/10 | | ||
while read -r idx invocation remaining; do | ||
i="$(( idx + 10 ))" | ||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${invocation}") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
done | ||
|
||
tail -n 10 "$TMP_DIR"/p10 | | ||
while read -r i invocation remaining; do | ||
Check warning Code scanning / shellcheck remaining appears unused. Verify use (or export if used externally). Warning
remaining appears unused. Verify use (or export if used externally).
|
||
idx="$(( i - 10 ))" | ||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
[[ $(journalctl --no-hostname -n 1 -t bash --invocation="${invocation}") =~ "invocation ${i} ${invocation}" ]] | ||
Check warning Code scanning / shellcheck Remove quotes from right-hand side of =~ to match as a regex rather than literally. Warning
Remove quotes from right-hand side of =~ to match as a regex rather than literally.
|
||
done |