From d503a49ed5609c725739b4a4036a814467667ff2 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Sep 2024 11:58:28 -0400 Subject: [PATCH] Update pull-logs.sh --- pull-logs.sh | 29 ++++++++++++++++++++++ swap.sh | 68 ---------------------------------------------------- 2 files changed, 29 insertions(+), 68 deletions(-) create mode 100644 pull-logs.sh delete mode 100644 swap.sh diff --git a/pull-logs.sh b/pull-logs.sh new file mode 100644 index 0000000..453cde4 --- /dev/null +++ b/pull-logs.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check if correct number of arguments are passed +if [ "$#" -ne 4 ]; then + echo "Usage: $0 " + 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" diff --git a/swap.sh b/swap.sh deleted file mode 100644 index 9afeae4..0000000 --- a/swap.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -# Function to create swap file -create_swapfile() { - # Detect the partition mounted on root ('/') - mount_point=$(df / | tail -1 | awk '{print $6}') - - # Get available space on the root partition in MB - available_space=$(df -BM $mount_point | tail -1 | awk '{print $4}' | sed 's/M//') - - # Calculate 5% of the available space in MB - swap_size=$((available_space * 5 / 100)) # 5% of available space in MB - - # Convert swap size from MB to GB - swap_size=$((swap_size / 1024)) # Convert MB to GB - - # Set upper limit of 30GB for the swap file - if [ $swap_size -gt 30 ]; then - swap_size=30 - fi - - # Abort if the calculated swap size is less than 1GB - if [ $swap_size -lt 1 ]; then - echo "Not enough disk space to create a swap file." - exit 1 - fi - - echo "Creating a ${swap_size}GB swap file at /swapfile..." - - # Remove existing swapfile if it exists - if [ -f /swapfile ]; then - sudo swapoff /swapfile - sudo rm /swapfile - echo "Existing swapfile removed." - fi - - # Create the swap file - sudo fallocate -l ${swap_size}G /swapfile - sudo chmod 600 /swapfile - sudo mkswap /swapfile - sudo swapon /swapfile - - echo "Swap file of ${swap_size}GB created and activated." -} - -# Function to persist the swap file across reboots -persist_swapfile() { - echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab - echo "Swap file added to /etc/fstab." -} - -# Check if --persist flag is passed -persist=false -if [ "$1" == "--persist" ]; then - persist=true -fi - -# Main script execution -create_swapfile - -if [ "$persist" = true ]; then - persist_swapfile -else - echo "Swap file will not persist after reboot." -fi - -# Show current swap status -sudo swapon --show