1
0
Fork 0
Pull specific logs from a specific time.
Go to file
colin cb0977160b send to hastebin. 2024-10-20 14:56:22 -04:00
README.md Update README.md 2024-09-28 12:05:06 -04:00
pull-logs.sh send to hastebin. 2024-10-20 14:56:22 -04:00

README.md

Log Retrieval Script

This script allows you to retrieve logs from a server based on a specified date and time range. It uses journalctl to extract logs within the provided time window, saving them to a file for easy access.

Features

  • Retrieves logs using journalctl from the specified start and end date/time.
  • Automatically saves the logs to a file for future reference.
  • Ensures logs are only retrieved within the given time frame.
  • Checks if journalctl is available on the system before execution.

Usage

curl -sSL https://git.nixc.us/colin/pull-logs/raw/branch/main/pull-logs.sh | bash -s -- 2024-09-28 11:35 5

Output

This script will:

  1. Collect logs from journalctl within the 5-minute range before and after the specified target time (Saturday, September 28, 2024, at 11:35 am).
  2. Search through relevant files in /var/log/ (such as syslog, auth.log, and kern.log).
  3. Check for logs from specific services (e.g., nginx, apache2, mysql).
  4. Print all logs to stdout for easy piping into a file.

You can pipe the output to a file:

curl -sSL https://git.nixc.us/colin/pull-logs/raw/branch/main/pull-logs.sh | bash -s -- 2024-09-28 11:35 5 > logs_output.txt

Notes

  • The script assumes all logs follow a standard timestamp pattern and will adjust based on the service if necessary.
  • If additional service logs are required, you can extend the service_logs array with the path to those log files.