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