2023-07-20 12:52:12 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-07-25 17:20:02 +02:00
|
|
|
#Use ./logger.sh <logfile> <relativepath>
|
2023-07-20 12:52:12 +02:00
|
|
|
|
2023-07-25 17:20:02 +02:00
|
|
|
# variables
|
|
|
|
REMOTE_PATH="$ES7_LOGS_PATH$2"
|
|
|
|
PUBLIC_LOG_URL="$ES7_LOGS_URL/$2"
|
2023-07-20 12:52:12 +02:00
|
|
|
|
2023-07-25 18:39:35 +02:00
|
|
|
# get file name in case of $1 is a path
|
|
|
|
file=$(basename -- "$1")
|
|
|
|
extension=${file##*.}
|
|
|
|
base=$(basename "${file%.*}")
|
|
|
|
|
2023-07-20 12:52:12 +02:00
|
|
|
# create remote folder to store logs if not exist
|
2023-07-25 18:39:35 +02:00
|
|
|
ssh $ES7_LOGS_SERVER_SSH "mkdir -p $REMOTE_PATH"
|
2023-07-20 12:52:12 +02:00
|
|
|
|
|
|
|
# Copy local logfile to remote destination
|
2023-07-25 17:20:02 +02:00
|
|
|
scp $1 "$ES7_LOGS_SERVER_SSH:$REMOTE_PATH"
|
|
|
|
|
|
|
|
# set correct permissions
|
2023-07-25 18:39:35 +02:00
|
|
|
ssh $ES7_LOGS_SERVER_SSH "chmod 644 $REMOTE_PATH$file"
|
2023-07-20 12:52:12 +02:00
|
|
|
|
|
|
|
# Clear x days old remote logs
|
2023-07-25 17:20:02 +02:00
|
|
|
ssh $ES7_LOGS_SERVER_SSH 'bash -s' << EOF
|
|
|
|
find $REMOTE_PATH -maxdepth 1 -mtime +$E7S_LOGS_PRESERVE_DAYS -exec "rm" -R {} \;
|
2023-07-20 12:52:12 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# return final log url
|
|
|
|
# change to txt if log is another text format
|
|
|
|
if [ $extension != "txt" ]; then
|
2023-07-25 17:20:02 +02:00
|
|
|
ssh $ES7_LOGS_SERVER_SSH "mv $REMOTE_PATH$file $REMOTE_PATH$base.txt"
|
2023-07-20 12:52:12 +02:00
|
|
|
fi
|
2023-07-25 18:39:35 +02:00
|
|
|
|
|
|
|
# set correct owner of webserver files
|
2023-07-25 18:41:51 +02:00
|
|
|
ssh $ES7_LOGS_SERVER_SSH "sudo chown -R www-data: $REMOTE_PATH"
|
2023-07-25 18:39:35 +02:00
|
|
|
|
2023-07-20 12:52:12 +02:00
|
|
|
echo "${PUBLIC_LOG_URL}${base}.txt"
|