22 lines
510 B
Bash
Executable File
22 lines
510 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Get the current date and time in YYYY-MM-DD-HHMMSS format
|
|
current_datetime=$(date +"%Y-%m-%d-%H%M%S")
|
|
|
|
# Archive name
|
|
archive_name="logs-$current_datetime.tar.gz"
|
|
|
|
# Create the logs directory if it doesn't exist
|
|
mkdir -p logs
|
|
|
|
# Create a tar.gz archive of all .log files
|
|
tar -czf "$archive_name" *.log
|
|
|
|
# Move the archive to the logs directory
|
|
mv "$archive_name" logs/
|
|
|
|
# Remove the original .log files
|
|
rm -f *.log
|
|
|
|
echo "Logs archived and moved to logs/ directory. Original log files removed."
|