Merge ~cjwatson/launchpad-bastion-scripts:rsync-scripts into launchpad-bastion-scripts:main

Proposed by Colin Watson
Status: Merged
Merged at revision: 7728bb9e90120de3e72c898f82ff43fafddf4efe
Proposed branch: ~cjwatson/launchpad-bastion-scripts:rsync-scripts
Merge into: launchpad-bastion-scripts:main
Diff against target: 96 lines (+78/-0)
3 files modified
rcat (+23/-0)
rless (+28/-0)
rtail (+27/-0)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+450565@code.launchpad.net

Commit message

Add rsync log-handling scripts from carob

Description of the change

We're moving the function of "system from which we can read Launchpad production logs" from carob to the PS5 Launchpad bastion, so it would be helpful to have some convenience scripts in `stg-launchpad`'s search path. People have been copying these around from my home directory for a while, so having them in revision control would be no bad thing.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/rcat b/rcat
2new file mode 100755
3index 0000000..26f2ad5
4--- /dev/null
5+++ b/rcat
6@@ -0,0 +1,23 @@
7+#!/bin/sh
8+
9+REMOTE=$1
10+TEMPFILE=$(mktemp)
11+
12+cleanup () {
13+ if [ "$SEED" ]; then
14+ cp -a "$TEMPFILE" "$SEED"
15+ fi
16+ rm -f "$TEMPFILE"
17+}
18+trap cleanup EXIT HUP INT QUIT TERM
19+
20+if [ "$SEED" ]; then
21+ cp -a "$SEED" "$TEMPFILE"
22+fi
23+rsync -q "$REMOTE" "$TEMPFILE"
24+case $REMOTE in
25+ *.gz) zcat "$TEMPFILE" ;;
26+ *.bz2) bzcat "$TEMPFILE" ;;
27+ *.xz) xzcat "$TEMPFILE" ;;
28+ *) cat "$TEMPFILE" ;;
29+esac
30diff --git a/rless b/rless
31new file mode 100755
32index 0000000..5d7829c
33--- /dev/null
34+++ b/rless
35@@ -0,0 +1,28 @@
36+#!/bin/sh
37+
38+REMOTE=$1
39+TEMPFILE=$(mktemp)
40+PATTERN=$2
41+
42+cleanup () {
43+ if [ "$SEED" ]; then
44+ cp -a "$TEMPFILE" "$SEED"
45+ fi
46+ rm -f "$TEMPFILE"
47+}
48+trap cleanup EXIT HUP INT QUIT TERM
49+
50+if [ "$SEED" ]; then
51+ cp -a "$SEED" "$TEMPFILE"
52+fi
53+case $REMOTE in
54+ *.gz) SHOW="zcat $TEMPFILE" ;;
55+ *.bz2) SHOW="bzcat $TEMPFILE" ;;
56+ *.xz) SHOW="xzcat $TEMPFILE" ;;
57+ *) SHOW="cat $TEMPFILE" ;;
58+esac
59+if [ "$PATTERN" ]; then
60+ SHOW="$SHOW | egrep \"$PATTERN\""
61+fi
62+rsync -q "$REMOTE" "$TEMPFILE"
63+eval "$SHOW" | less
64diff --git a/rtail b/rtail
65new file mode 100755
66index 0000000..035f55b
67--- /dev/null
68+++ b/rtail
69@@ -0,0 +1,27 @@
70+#!/bin/sh
71+
72+REMOTE=$1
73+TEMPFILE=$(mktemp)
74+PATTERN=$2
75+
76+cleanup () {
77+ if [ "$SEED" ]; then
78+ cp -a "$TEMPFILE" "$SEED"
79+ fi
80+ rm -f "$TEMPFILE"
81+}
82+trap cleanup EXIT HUP INT QUIT TERM
83+
84+if [ "$SEED" ]; then
85+ cp -a "$SEED" "$TEMPFILE"
86+fi
87+case $REMOTE in
88+ *.gz) SHOW="zcat $TEMPFILE" ;;
89+ *.bz2) SHOW="bzcat $TEMPFILE" ;;
90+ *.xz) SHOW="xzcat $TEMPFILE" ;;
91+ *) SHOW="cat $TEMPFILE" ;;
92+esac
93+if [ "$PATTERN" ]; then
94+ SHOW="$SHOW | egrep \"$PATTERN\""
95+fi
96+watch -n5 "rsync -q $REMOTE $TEMPFILE; $SHOW | tail -n$(($(tput lines) - ${ROWS_GRACE:-6})) | cut -c1-$(tput cols)"

Subscribers

People subscribed via source and target branches