summaryrefslogtreecommitdiffstats
path: root/rescue/tree/usr/sbin/grabjournallogs
diff options
context:
space:
mode:
authorFrancesc Pinyol Margalef <francesc.pinyol.m@gmail.com>2013-12-21 13:37:33 +0100
committerFrancesc Pinyol Margalef <francesc.pinyol.m@gmail.com>2013-12-21 13:37:33 +0100
commit095c6b25885ce3d22eedba8cdb98f1fd7e8708a5 (patch)
tree5bfc768996b3ddec185abeb02b602b48b14d10db /rescue/tree/usr/sbin/grabjournallogs
parentdf60191bdbddfa7c8e5bd11a2578aae6740963c0 (diff)
parentf76dc0931e47338aa9c7db257d28e5015d8a2f47 (diff)
downloaddrakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.gz
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.bz2
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.xz
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.zip
Merge branch 'master' of git://git.mageia.org/software/drakx
Diffstat (limited to 'rescue/tree/usr/sbin/grabjournallogs')
-rwxr-xr-xrescue/tree/usr/sbin/grabjournallogs51
1 files changed, 51 insertions, 0 deletions
diff --git a/rescue/tree/usr/sbin/grabjournallogs b/rescue/tree/usr/sbin/grabjournallogs
new file mode 100755
index 000000000..ef2ea4a1d
--- /dev/null
+++ b/rescue/tree/usr/sbin/grabjournallogs
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+if ! mountpoint -q /mnt ; then
+ echo "I do not seem to see a Mageia install mounted on /mnt. You need to mount it first!" >&2
+ exit 1
+fi
+
+if [ ! -f /mnt/etc/machine-id ]; then
+ echo "Cannot find machine-id file (/mnt/etc/machine-id)" >&2
+ exit 1
+fi
+
+MID=$(cat /mnt/etc/machine-id)
+echo
+echo "Found machine-id: $MID"
+if [ ! -d /mnt/var/log/journal/$MID ]; then
+ echo "Cannot find journal log directory (/mnt/var/log/journal/<machine-id>)" >&2
+ exit 1
+fi
+
+TIMEFRAME=24
+if [ -n "$1" ]; then
+ NEWTIMEFRAME=$(( 0 + $1 ))
+ if [ $NEWTIMEFRAME -gt 0 ]; then
+ TIMEFRAME=$NEWTIMEFRAME
+ fi
+fi
+SINCE="$(LC_ALL=c date --date=$TIMEFRAME' hours ago' +'%F %T')"
+echo "Will collect logs from the last $TIMEFRAME hour(s)"
+echo " NB give numeric argument to override capture period"
+
+TEMPFILE=$(mktemp /tmp/grabjournallogs.XXXXXX)
+echo -n "Extracting logs... "
+journalctl -D /mnt/var/log/journal/$MID --since "$SINCE" -o short >$TEMPFILE
+echo "done"
+
+if [ $(cat $TEMPFILE | wc -l) -lt 2 ]; then
+ rm -f $TEMPFILE
+ echo >&2
+ echo "Cannot find any logs. Consider increasing the capture period by passing a" >&2
+ echo "numeric argument larger than $TIMEFRAME." >&2
+ exit 1
+fi
+
+echo -n "Compressing logs... "
+cat $TEMPFILE | xz >/journallogs.xz
+rm -f $TEMPFILE
+echo "done"
+
+echo
+echo "Your logs have been extracted to the file 'journallogs.xz'"