forked from colin/disk-space-report
30 lines
864 B
Bash
30 lines
864 B
Bash
#!/bin/bash
|
|
|
|
# Check if correct number of arguments are passed
|
|
if [ "$#" -ne 4 ]; then
|
|
echo "Usage: $0 <start-date> <start-time> <end-date> <end-time>"
|
|
echo "Example: $0 2024-09-26 08:00:00 2024-09-26 12:00:00"
|
|
exit 1
|
|
fi
|
|
|
|
START_DATE=$1
|
|
START_TIME=$2
|
|
END_DATE=$3
|
|
END_TIME=$4
|
|
|
|
# Combine date and time into the format expected by journalctl
|
|
START="$START_DATE $START_TIME"
|
|
END="$END_DATE $END_TIME"
|
|
|
|
# Check if journalctl is available on the server
|
|
if ! command -v journalctl &> /dev/null
|
|
then
|
|
echo "journalctl could not be found. Please install it first."
|
|
exit 1
|
|
fi
|
|
|
|
# Fetch logs from the given date/time range
|
|
journalctl --since="$START" --until="$END" > /tmp/logs_${START_DATE}_${START_TIME}_to_${END_DATE}_${END_TIME}.log
|
|
|
|
echo "Logs from $START to $END have been saved to /tmp/logs_${START_DATE}_${START_TIME}_to_${END_DATE}_${END_TIME}.log"
|