Script started on 2024-08-07 11:48:51+00:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="133" LINES="37"]
]0;ubuntu@bastion: ~[01;32mubuntu@bastion[00m:[01;34m~[00m$ cd bin
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ./recordslog.sh 
./recordslog.sh: line 1: i#!/bin/bash: No such file or directory
Activated service account credentials for: [logbucket@nitrox-415207.iam.gserviceaccount.com]
Copying file:///etc/records-new/records/ubuntu_cmd_2024-08-07_11-33-56.log [Content-Type=application/octet-stream]...
/ [0 files][    0.0 B/ 36.7 KiB]                                                / [1 files][ 36.7 KiB/ 36.7 KiB]                                                Copying file:///etc/records-new/records/ubuntu_cmd_2024-08-07_11-48-51.log [Content-Type=application/octet-stream]...
/ [1 files][ 36.7 KiB/ 36.7 KiB]                                                / [2 files][ 36.7 KiB/ 36.7 KiB]                                                Copying file:///etc/records-new/records/ubuntu_time_2024-08-07_11-33-56.log [Content-Type=application/octet-stream]...
/ [2 files][ 36.7 KiB/ 47.5 KiB]                                                / [3 files][ 47.5 KiB/ 47.5 KiB]                                                ^CCaught CTRL-C (signal 2) - exiting
]0;ubuntu@bastion: ~/bin[01;32mubuntu@bastion[00m:[01;34m~/bin[00m$ ./recordslog.sh [10Pcd bin[2Pexitsudo vi recordslog.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" 39L, 1116C[2;1H▽[6n[2;1H  [1;1H[>c]10;?]11;?[1;1H[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-new[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
sudo [38;5;130mmkdir[m [35m-p[m [35m$NEW_FOLDER[m

[34m# Copy log file data to the new folder[m
sudo cp [35m-r[m /etc/records/ [35m$NEW_FOLDER[m/

[34m# Get the latest two files in the log folder[m
 [36mLATEST_FILES[m=[35m$([m[35msudo [m[38;5;130mls[m[35m -1t /etc/records/[m[35m$whoami_[m[35m* [m[38;5;130m|[m[35m head -n [m[31m2[m[35m)[m

[34m# Extract filenames to keep[m
[36mFILES_TO_KEEP[m=[35m$([m[38;5;130mecho[m[31m [m[35m$LATEST_FILES[m[31m [m[38;5;130m|[m[35m xargs -n [m[31m1[m[35m basename [m[38;5;130m|[m[35m tr [m[38;5;130m'[m[31m\n[m[38;5;130m'[m[35m [m[38;5;130m'[m[31m [m[38;5;130m'[m[35m)[m

[34m# Remove all files except the latest two[m
[38;5;130mfor[m FILE [38;5;130min[m [35m$([m[35msudo [m[38;5;130mls[m[35m /etc/records[m[35m)[m; [38;5;130mdo
[m    [38;5;130mif ![m [38;5;130mecho[m[31m [m[35m$FILES_TO_KEEP[m[31m [m[38;5;130m|[m [38;5;130mgrep[m [35m-qw[m [35m$FILE[m[38;5;130m;[m [38;5;130mthen[m[22;9Hsudo [38;5;130mrm[m [38;5;130m-f[m /etc/records/[35m$FILE[m[38;5;130m;
[m    [38;5;130mfi;
done[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
sudo gsutil cp [35m-r[m [35m$NEW_FOLDER[m [35m$DESTINATION[m

[34m# Optionally, remove the local copy after upload[m
sudo [38;5;130mrm[m [35m-rf[m [35m$NEW_FOLDER[m

[38;5;130mecho[m[31m [m[38;5;130m"[m[31mLog file uploaded and original file cleared, except for the latest two files.[m[38;5;130m"[m[37;116H39,0-1[8CBot[36;1H[?25h[?25l[37;106Hi[36;1H[37;106H [36;1H
[1m-- INSERT --[m[37;13H[K[37;116H39,1[10CBot[36;1H[?25h[?25l[37;117H8[35;1H[?25h[?25l[37;117H7[34;1H[?25h[?25l