-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·34 lines (29 loc) · 1.42 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·34 lines (29 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Script Name: Ops Challenge: Clearing Logs
# Author: Juan Miguel Cano
# Date of latest revision: 12/01/2023
# Purpose: Create a fake log, compresses it, clears its contents,
# cont: and prints info on the compression process.
# Execution: bash 301Ops5.sh
# Resources:
touch "my-log-file.txt"
echo "Pinto Bean for Dogs generated by Juan ... " >> my-log-file.txt
cat my-log-file.txt
mkdir -p "backups" # Ensure the directory is created even if it already exists
LOG_FILES=("my-log-file.txt") # Correct the array name
BACKUP_DIR="backups" # Correct the variable name
TIMESTAMP=$(date +"%m%d%Y") # Add a closing quote
for file in "${LOG_FILES[@]}"; do
FILE_NAME=$(basename "$file" .txt)
FILE_SIZE=$(wc -c "$file" | awk '{print $1}')
zip -r "$BACKUP_DIR/$FILE_NAME-$TIMESTAMP.zip" "$file"
cat /dev/null > "$file"
COMPRESSED_FILE_SIZE=$(wc -c "$BACKUP_DIR/$FILE_NAME-$TIMESTAMP.zip" | awk '{print $1}')
echo "File size before compression: $FILE_SIZE"
echo "File size after compression: $COMPRESSED_FILE_SIZE"
if [[ $FILE_SIZE -gt $COMPRESSED_FILE_SIZE ]]; then
echo "Compression successful: compressed file size is smaller than original file size"
else
echo "Compression unsuccessful: compressed file size is larger than original file size"
fi
done