my-scripts/SaveX11crash.sh
2021-11-25 19:57:30 +01:00

48 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# SaveX11crash.sh save the X11 logs and the journalctl of the last 10 minutes
#
# (c) GPL by Ulf Bartholomäus ub1x@gmx.net
VERSION="$( basename $0 ) Version 0.1.1 from 25.11.2021"
#
# Input: n/a
# Output: progress and 7z compressed logs
# Returnvalue: 0 if finished OK and 10 if there was an issue at 7z
#
# Changes:
# 0.1.1
# Detect if not root
# 0.1.0
# Initial version
## Verwendeten Pfad mit Datum und Uhrzeit definieren - da sich die Sekunden ändern könnten
MyPath="${HOME}/X11-Crash_$(date +%F_%H-%M-%S)"
MyTime="-10m" # -10m = die letzten 10 minuten
## teste ob root rechte vorhanden
if [ "`whoami`" != "root" ] ; then
echo -e "Nicht ausreichend Rechte - bitte als "root" anmelden!\nsu -c $0"
exit 20
fi
## Pfad anlegen
mkdir -p ${MyPath}
## X11 Logs in aktuellen Pfad Sichern sowie journal der letzten 10min erstellen
echo -e "Sicher X11 logs:"
cp -v /var/log/Xorg.* ${MyPath}/
journalctl -xe --since ${MyTime} >> ${MyPath}/journalctl_${MyTime}.log
echo -e "Sicher journalctl von <${MyTime}>"
## Packe die Logs und mache es für alle änderbar (exit falls Problem)
7za a "${MyPath}.7z" "${MyPath}" || exit 10
## Ordner wieder löschen und rechte auf für alle lese und schreibbar
rm -rf "${MyPath}"
chmod a+rw "${MyPath}.7z"
## Verschiebe 7z
echo -e "Verschieb Logs in </tmp> damit auch für normale Benutzer zugreifbar zu machen"
mv -v "${MyPath}.7z" /tmp