Script started on 2024-08-07 10:23:43+00:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="133" LINES="37"]
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ cd /etc/records/
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls
ubuntu_cmd_2024-08-07_10-14-44.log  ubuntu_cmd_2024-08-07_10-23-43.log   ubuntu_time_2024-08-07_10-23-39.log
ubuntu_cmd_2024-08-07_10-23-39.log  ubuntu_time_2024-08-07_10-14-44.log  ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ll [K[Ks -atr
[0m[01;34m..[0m                                   ubuntu_time_2024-08-07_10-23-39.log  [30;42m.[0m
ubuntu_time_2024-08-07_10-14-44.log  ubuntu_cmd_2024-08-07_10-23-39.log   ubuntu_time_2024-08-07_10-23-43.log
ubuntu_cmd_2024-08-07_10-14-44.log   ubuntu_cmd_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls -atr[1Ptr
ubuntu_time_2024-08-07_10-14-44.log  ubuntu_time_2024-08-07_10-23-39.log  ubuntu_cmd_2024-08-07_10-23-43.log
ubuntu_cmd_2024-08-07_10-14-44.log   ubuntu_cmd_2024-08-07_10-23-39.log   ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls -tr[C[K[Kltr
total 40
-rw-rw-r-- 1 ubuntu ubuntu  4924 Aug  7 10:23 ubuntu_time_2024-08-07_10-14-44.log
-rw-rw-r-- 1 ubuntu ubuntu 22634 Aug  7 10:23 ubuntu_cmd_2024-08-07_10-14-44.log
-rw-rw-r-- 1 ubuntu ubuntu   180 Aug  7 10:23 ubuntu_time_2024-08-07_10-23-39.log
-rw-rw-r-- 1 ubuntu ubuntu   423 Aug  7 10:23 ubuntu_cmd_2024-08-07_10-23-39.log
-rw-rw-r-- 1 ubuntu ubuntu     0 Aug  7 10:23 ubuntu_cmd_2024-08-07_10-23-43.log
-rw-rw-r-- 1 ubuntu ubuntu     0 Aug  7 10:23 ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls -1t ${USER}_* | head -n 2
ubuntu_time_2024-08-07_10-23-43.log
ubuntu_cmd_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ cd
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ d[Kcd bin
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ s
s: command not found
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls
[0m[01;32maudit.sh[0m  [01;32mcpu_and_memory.sh[0m  [01;32mlog.sh[0m  [01;32mrecordslog.sh[0m  service.json  [01;32mstart_slack.sh[0m
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ cat recordslog.sh 
#!/bin/bash

# Variables
LOG_FOLDER="/etc/records/"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
NEW_FOLDER="/etc/records_$DATE"
BUCKET_NAME="nitrologbucket"
DESTINATION="gs://$BUCKET_NAME/$DATE/"
SERVICE_ACCOUNT_KEY="/home/ubuntu/bin/service.json"

# Create a new folder with the current date and time
mkdir -p "$NEW_FOLDER"

# Copy log file data to the new folder
cp -r "$LOG_FOLDER"/* "$NEW_FOLDER"

# Clear the original log file
rm -rf "$LOG_FOLDER"/*

# Authenticate with GCP
gcloud auth activate-service-account --key-file="$SERVICE_ACCOUNT_KEY"

# Upload the new folder to GCP bucket
gsutil cp -r "$NEW_FOLDER" "$DESTINATION"

# Optionally, remove the local copy after upload
rm -rf "$NEW_FOLDER"

echo "Log file uploaded and original file cleared."

]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LOG_FOLDER="/etc/records/"
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1P[1@-
ls: cannot access '/etc/records/ubuntu-*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(ls -1t "${LOG_FOLDER}${USER}-*" | head -n 2)[1@s[1@u[1@d[1@o[1@ 
ls: cannot access '/etc/records/ubuntu-*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)-[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[5P[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C_[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[33POG_FOLDER="/etc/records/"[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[8Pcat recordslog.sh ls[K[1Pscd bin[Kls -1t ${USER}_* | head -n 2ltr[K1t ${USER}_* | head -n 2
ls: cannot access 'ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls -1t ${USER}_* | head -n 2[C[C[C[C[C[C[C[1@/[1@e[1@t[2@c/[1@r[1@e[1@c[5@ords/[7@ubuntu_
ubuntu_cmd_2024-08-07_10-14-44.log   ubuntu_cmd_2024-08-07_10-23-43.log   ubuntu_time_2024-08-07_10-23-39.log
ubuntu_cmd_2024-08-07_10-23-39.log   ubuntu_time_2024-08-07_10-14-44.log  ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls -1t /etc/records/ubuntu_${USER}_* | head -n 2[1P[1P[1P[1P[1P[1P[1P
/etc/records/ubuntu_time_2024-08-07_10-23-43.log
/etc/records/ubuntu_cmd_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls -1t /etc/records/${USER}_* | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[13P[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[CLATEST_FILES=$(sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ U[KUSER=$WHOAMI
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ USER=$WHOAMI[KECHO [K[K[K[K[Kecho$[K $USER

]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ echo $USERUSER=$WHOAMI[K[K[K[K[K[K[Kwhami[K[K[Koami
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ USER=whoami[1Pecho $USER
whoami
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ USER=$(whoami)
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ USER=$(whoami)[4Pecho $USER
ubuntu
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ echo $USERUSER=$(whoami)[4Pecho $USERUSER=whoami[1Pecho $USERUSER=$WHOAMIls -1t /etc/records/${USER}_* | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[13P[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[CLATEST_FILES=$(sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)-[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C_[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ (sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2
> (sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[K^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ (sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[1P
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[Kecho $LOG
$LOGNAME     $LOG_FOLDER  
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ echo $LOG
$LOGNAME     $LOG_FOLDER  
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ echo $LOG_FOLDER 
/etc/records/
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ /etc/recordsls -1t /etc/records/${USER}_* | head -n 2^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls -1t /etc/records/${USER}_* | head -n 2
/etc/records/ubuntu_cmd_2024-08-07_10-23-43.log
/etc/records/ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ 
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ 
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ 
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ r[K(reverse-i-search)`':[Cr': ls -1t /etc/records/${USER}_* | head -n 2[1@e[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1@c[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1@o[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1@r[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1@d[C[C[C[C[C[C[C[C[C[C[C[C[C[C[Cu': sudo chown :recordusers /home/ubuntu/bin/audit.sh [14Pusermod -aG recordusers ubuntu[7P]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ [C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[K[K[K[K[K[K[Kroot
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo usermod -aG recordusers rootls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[7Pls -1t /etc/records/${USER}_*[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[7@sudo ls -1t "${LOG_FOLDER}${USER}_*"[C[C[C[C[C[C[C[C[C[C[C[C
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[15Pusermod -aG recordusers rootls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[Ksudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[15Pusermod -aG recordusers rootls -1t "${LOG_FOLDER}${USER}_*" | head -n 2[1P[1P[1P[1P[1P[1P[1P[1P[1P[1P[1P[1P[1P[1@/[1@e[1@t[2@c/[1@r[1@e[1@c[5@ords/
ls: cannot access '/etc/records/ubuntu_*': No such file or directory
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo ls -1t "/etc/records/${USER}_*" | head -n 2[1P[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1P
/etc/records/ubuntu_cmd_2024-08-07_10-23-43.log
/etc/records/ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo ls -1t /etc/records/${USER}_* | head -n 2[2@"/etc/records/${USER}_*"[C[C[C[C[C[C[C[C[C[C[C[C${LOG_FOLDER}[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1P[1P
/etc/records/ubuntu_cmd_2024-08-07_10-23-43.log
/etc/records/ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ FILES_TO_KEEP=$(echo "$LATEST_FILES" | xargs -n 1 basename | tr '\n' ' ')
basename: missing operand
Try 'basename --help' for more information.
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ FILES_TO_KEEP=$(echo "$LATEST_FILES" | xargs -n 1 basename | tr '\n' ' ')^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(sudo ls -1t "${LOG_FOLDER}${USER}_*" | head -n 2)[C[C[1P[1P
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ LATEST_FILES=$(sudo ls -1t ${LOG_FOLDER}${USER}_* | head -n 2)[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[CFILES_TO_KEEP=$(echo "$LATEST_FILES" | xargs -n 1 basename | tr '\n' ' ')
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ echo $FILES_TO_KEEP 
ubuntu_cmd_2024-08-07_10-23-43.log ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo find "$LOG_FOLDER" -type f ! -name "$(echo $FILES_TO_KEEP | tr ' ' ' -name ' -name ')" -exec rm -f {} +
> 
> ^C
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ for FILE in $(sudo ls "$LOG_FOLDER"); do
>   if ! echo "$FILES_TO_KEEP" | grep -qw "$FILE"; then
>     sudo rm -f "$LOG_FOLDER/$FILE"
>   fi
> done
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ cd /etc/records/
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ l
ubuntu_cmd_2024-08-07_10-23-43.log  ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls
ak_cmd_2024-08-07_11-02-29.log   ubuntu_cmd_2024-08-07_10-23-43.log
ak_time_2024-08-07_11-02-29.log  ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls[Kcd /etc/records/for FILE in $(sudo ls "$LOG_FOLDER"); do   if ! echo "$FILES_TO_KEEP" | grep -qw "$FILE"; then     sudo rm -f "$LOG_FOLDER/$FILE";   fi; done
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ ls
ubuntu_cmd_2024-08-07_10-23-43.log  ubuntu_time_2024-08-07_10-23-43.log
]0;ubuntu@bastion: /etc/records[01;32mubuntu@bastion[00m:[01;34m/etc/records[00m$ cd
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ s
s: command not found
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ cd 
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ ls
[0m[01;34mbin[0m  [01;34msnap[0m
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ cd v[Kbin
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ls
[0m[01;32maudit.sh[0m  [01;32mcpu_and_memory.sh[0m  [01;32mlog.sh[0m  [01;32mrecordslog.sh[0m  service.json  [01;32mstart_slack.sh[0m
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ dfo[K[K[Kdu[K[K> recordslog.sh 
bash: recordslog.sh: Permission denied
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ > recordslog.sh [1@s[1@u[1@d[1@o[1@ 
bash: recordslog.sh: Permission denied
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ sudo vi reec[K[Kcordslog.sh 
[?1049h[22;0;0t[>4;2m[?1h=[?2004h[1;37r[?12h[?12l[22;2t[22;1t[27m[23m[29m[m[H[2J[?25l[37;1H"recordslog.sh" 30L, 747C[2;1H▽[6n[2;1H  [1;1H[>c]10;?]11;?[1;1H[34m#!/bin/bash

# Variables[m
[36mLOG_FOLDER[m=[38;5;130m"[m[31m/etc/records/[m[38;5;130m"[m
[36mDATE[m=[35m$([m[35mdate +[m[38;5;130m"[m[31m%Y-%m-%d_%H-%M-%S[m[38;5;130m"[m[35m)[m
[36mNEW_FOLDER[m=[38;5;130m"[m[31m/etc/records_[m[35m$DATE[m[38;5;130m"[m
[36mBUCKET_NAME[m=[38;5;130m"[m[31mnitrologbucket[m[38;5;130m"[m
[36mDESTINATION[m=[38;5;130m"[m[31mgs://[m[35m$BUCKET_NAME[m[31m/[m[35m$DATE[m[31m/[m[38;5;130m"[m
[36mSERVICE_ACCOUNT_KEY[m=[38;5;130m"[m[31m/home/ubuntu/bin/service.json[m[38;5;130m"[m

[34m# Create a new folder with the current date and time[m
[38;5;130mmkdir[m [35m-p[m [38;5;130m"[m[35m$NEW_FOLDER[m[38;5;130m"[m

[34m# Copy log file data to the new folder[m
cp [35m-r[m [38;5;130m"[m[35m$LOG_FOLDER[m[38;5;130m"[m/* [38;5;130m"[m[35m$NEW_FOLDER[m[38;5;130m"[m

[34m# Clear the original log file[m
[38;5;130mrm[m [35m-rf[m [38;5;130m"[m[35m$LOG_FOLDER[m[38;5;130m"[m/*

[34m# Authenticate with GCP[m
gcloud auth activate-service-account [35m--key-file=[m[38;5;130m"[m[35m$SERVICE_ACCOUNT_KEY[m[38;5;130m"[m

[34m# Upload the new folder to GCP bucket[m
gsutil cp [35m-r[m [38;5;130m"[m[35m$NEW_FOLDER[m[38;5;130m"[m [38;5;130m"[m[35m$DESTINATION[m[38;5;130m"[m

[34m# Optionally, remove the local copy after upload[m
[38;5;130mrm[m [35m-rf[m [38;5;130m"[m[35m$NEW_FOLDER[m[38;5;130m"

echo[m[31m [m[38;5;130m"[m[31mLog file uploaded and original file cleared.[m[38;5;130m"[m

[94m~                                                                                                                                    [32;1H~                                                                                                                                    [33;1H~                                                                                                                                    [34;1H~                                                                                                                                    [35;1H~                                                                                                                                    [36;1H~                                                                                                                                    [m[37;116H30,0-1[8CAll[30;1H[?25h[?25l[37;106H^[[30;1H[37;106H  [30;1H[37;106H^[[30;1H[37;106H  [30;1H[?25h[?25l[37;106Hd[30;1H[?25h[?25l[37;107Hd[30;1H[37;106H  [29;1H
[94m~                                                                                                                                    [m[37;116H29,1  [29;1H[?25h[?25l[37;106Hd[29;1H[?25h[?25l[37;107Hd[29;1H[37;106H  [28;1H
[94m~                                                                                                                                    [m[37;117H8,0-1[28;1H[?25h[?25l[37;106Hd[28;1H[?25h[?25l[37;107Hd[28;1H[37;106H  [27;1H
[94m~                                                                                                                                    [m[37;117H7,1  [27;1H[?25h[?25l[37;106Hd[27;1H[?25h[?25l[37;107Hd[27;1H[37;106H  [26;1H
[94m~                                                                                                                                    [m[37;117H6[26;1H[?25h[?25l[37;106Hd[26;1H[?25h[?25l[37;107Hd[26;1H[37;106H  [25;1H
[94m~                                                                                                                                    [m[37;117H5,0-1[25;1H[?25h[?25l[37;106Hd[25;1H[?25h[?25l[37;107Hd[25;1H[37;106H  [24;1H
[94m~                                                                                                                                    [m[37;117H4,1  [24;1H[?25h[?25l[37;106Hd[24;1H[?25h[?25l[37;107Hd[24;1H[37;106H  [23;1H
[94m~                                                                                                                                    [m[37;117H3[23;1H[?25h[?25l[37;106Hd[23;1H[?25h[?25l[37;107Hd[23;1H[37;106H  [22;1H
[94m~                                                                                                                                    [m[37;117H2,0-1[22;1H[?25h[?25l[37;106Hd[22;1H[?25h[?25l[37;107Hd[22;1H[37;106H  [21;1H
[94m~                                                                                                                                    [m[37;117H1,1  [21;1H[?25h[?25l[37;106Hd[21;1H[?25h[?25l[37;107Hd[21;1H[37;106H  [20;1H
[94m~                                                                                                                                    [m[37;117H0[20;1H[?25h[?25l[37;106Hd[20;1H[?25h[?25l[37;107Hd[20;1H[37;106H  [19;1H
[94m~                                                                                                                                    [m[37;116H19,0-1[19;1H[?25h[?25l[37;106Hd[19;1H[?25h[?25l[37;107Hd[19;1H[37;106H  [18;1H
[94m~                                                                                                                                    [m[37;117H8,1  [18;1H[?25h[?25l[37;106Hd[18;1H[?25h[?25l[37;107Hd[18;1H[37;106H  [17;1H
[94m~                                                                                                                                    [m[37;117H7[17;1H[?25h[?25l[37;106Hd[17;1H[?25h[?25l[37;107Hd[17;1H[37;106H  [16;1H
[94m~                                                                                                                                    [m[37;117H6,0-1[16;1H[?25h[?25l[37;106Hd[16;1H[?25h[?25l[37;107Hd[16;1H[37;106H  [15;1H
[94m~                                                                                                                                    [m[37;117H5,1  [15;1H[?25h[?25l[37;106Hd[15;1H[?25h[?25l[37;107Hd[15;1H[37;106H  [14;1H
[94m~                                                                                                                                    [m[37;117H4[14;1H[?25h[?25l[37;106Hd[14;1H[?25h[?25l[37;107Hd[14;1H[37;106H  [13;1H
[94m~                                                                                                                                    [m[37;117H3,0-1[13;1H[?25h[?25l[37;106Hd[13;1H[?25h[?25l[37;107Hd[13;1H[37;106H  [12;1H
[94m~                                                                                                                                    [m[37;117H2,1  [12;1H[?25h[?25l[37;106Hd[12;1H[?25h[?25l[37;107Hd[12;1H[37;106H  [11;1H
[94m~                                                                                                                                    [m[37;117H1[11;1H[?25h[?25l[37;106Hd[11;1H[?25h[?25l[37;107Hd[11;1H[37;106H  [10;1H
[94m~                                                                                                                                    [m[37;117H0,0-1[10;1H[?25h[?25l[37;106Hd[10;1H[?25h[?25l[37;107Hd[10;1H[37;106H  [9;1H
[94m~                                                                                                                                    [m[37;116H9,1   [9;1H[?25h[?25l[37;106Hd[9;1H[?25h[?25l[37;107Hd[9;1H[37;106H  [8;1H
[94m~                                                                                                                                    [m[37;116H8[8;1H[?25h[?25l[37;106Hd[8;1H[?25h[?25l[37;107Hd[8;1H[37;106H  [7;1H
[94m~                                                                                                                                    [m[37;116H7[7;1H[?25h[?25l[37;106Hd[7;1H[?25h[?25l[37;107Hd[7;1H[37;106H  [6;1H
[94m~                                                                                                                                    [m[37;116H6[6;1H[?25h[?25l[37;106Hd[6;1H[?25h[?25l[37;107Hd[6;1H[37;106H  [5;1H
[94m~                                                                                                                                    [m[37;116H5[5;1H[?25h[?25l[37;106Hd[5;1H[?25h[?25l[37;107Hd[5;1H[37;106H  [4;1H
[94m~                                                                                                                                    [m[37;116H4[4;1H[?25h[?25l[37;106Hd[4;1H[?25h[?25l[37;107Hd[4;1H[37;106H  [3;1H
[94m~                                                                                                                                    [m[37;116H3[3;1H[?25h[?25l[37;106Hd[3;1H[?25h[?25l[37;107Hd[3;1H[37;106H  [2;1H
[94m~                                                                                                                                    [m[37;116H2,0-1[2;1H[?25h[?25l[37;106Hd[2;1H[?25h[?25l[37;107Hd[2;1H[37;106H  [1;1H
[94m~                                                                                                                                    [m[37;116H1,1  [1;1H[?25h[?25l[37;106Hd[1;1H[?25h[?25l[37;107Hd[1;1H[37;106H  [1;1H[1;1H[K[37;1H--No lines in buffer--[37;23H[K[37;116H0,0-1[9CAll[1;1H[?25h[?25l[37;106Hd[1;1H[?25h[?25l[37;107Hd[1;1H[37;106H  [1;1H[?25h[?25l[37;106Hi[1;1H[37;106H [1;1H[37;1H[1m-- INSERT --[m[37;13H[K[37;116H0,1[11CAll[1;1H[?25h[?25l[34m#!/bin/bash[m[2;1H[K[3;1H[34m# Variables[m[3;12H[K[4;1H[36mUSER[m=[35m$([m[35mwhoami[m[35m)[m [34m# or replace with [m[4;34H[K[4;34H[?25h[?25l[34myour specific username if needed[m
[36mLOG_FOLDER[m=[38;5;130m"[m[31m/etc/records/[m[38;5;130m"[m[5;27H[K[6;1HDATE[6;5H[K[6;5H[?25h[?25l[36mDATE[m=[35m$([m[35mdate +[m[38;5;130m"[m[31m%Y-%m-%d_%H-%M-%S[m[38;5;130m"[m[35m)[m
[36mNEW_FOLDER[m=[38;5;130m"[m[31m/etc/records_[m[35m$DATE[m[38;5;130m"[m[7;32H[K[8;1HB[8;2H[K[8;2H[?25h[?25l[36mBUCKET_NAME[m=[38;5;130m"[m[31mnitro[?25h[?25llogbucket[m[38;5;130m"[m
[36mDESTINATION[m=[38;5;130m"[m[31mgs://[m[35m$BUCKET_NAME[m[31m/[m[35m$DATE[m[31m/[m[38;5;130m"[m[9;39H[K[10;1HSERVICE_[10;9H[K[10;9H[?25h[?25l[36mSERVICE_ACCOUNT_KEY[m=[38;5;130m"[m[31m/home/ubuntu/bin/service.json[m[38;5;130m"[m[11;1H[K[12;1H[34m# Create a new[m[12;15H[K[12;15H[?25h[?25l[34m folder with the current date and time[m
sudo [38;5;130mmkdir[m [35m-p[m [38;5;130m"[m[35m$NEW_FO[m[13;23H[K[13;23H[?25h[?25l[35mLDER[m[38;5;130m"[m[14;1H[K[15;1H[34m# Copy log file data to the new folder[m[15;39H[K[16;1Hsudo cp [35m-r[m [38;5;130m"[m[35m$LO[m[16;16H[K[16;16H[?25h[?25l[35mG_FOLDER[m[38;5;130m"[m/* [38;5;130m"[m[35m$NEW_FOLDER[m[38;5;130m"[m[17;1H[K[18;1H[34m# Get the latest two files in the l[m[18;36H[K[18;36H[?25h[?25l[34mog folder[m
[36mLATEST_FILES[m=[35m$([m[35msudo [m[38;5;130mls[m[35m -1t [m[38;5;130m"[m[35m${LOG_FOLDER}${USER}[m[31m_*[m[38;5;130m"[m[35m [m[19;53H[K[19;53H[?25h[?25l[38;5;130m|[m[35m head -n [m[31m2[m[35m)[m[20;1H[K[21;1H[34m# Extract filenames to keep[m[21;28H[K[22;1H[36mFILES_TO_KEEP[m=[35m$([m[38;5;130mecho[m[31m [m[22;22H[K[22;22H[?25h[?25l[38;5;130m"[m[35m$LATEST_FILES[m[38;5;130m"[m[31m [m[38;5;130m|[m[35m xargs -n [m[31m1[m[35m basename [m[38;5;130m|[m[35m t