#!/bin/bash parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" SERVER_IP=friday DOWNLOADS="" MOUNT="" # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in --downloads) DOWNLOADS="$2" shift 2 ;; --mount) MOUNT="$2" shift 2 ;; *) echo "Unknown option: $1" exit 1 ;; esac done if [ -z "$DOWNLOADS" ] || [ -z "$MOUNT" ]; then echo "Usage: $0 --downloads --mount " exit 1 fi # Extract the folder name from the last part of the MOUNT path FOLDER_NAME=$(basename "$MOUNT") ping -c1 -W2 "$SERVER_IP" > /dev/null 2>&1 if [[ $? -eq 0 ]]; then if mountpoint -q "$MOUNT"; then echo "$FOLDER_NAME mounted. Copying files." | ts '[%Y-%m-%d %H:%M:%S]' files=$(ls "$MOUNT") # Trigger drive spin up sleep 5 output=$(rsync -avzh --update --stats --exclude '.gitkeep' "$DOWNLOADS" "$MOUNT" | grep -A 1 'files transferred') files=$(echo "$output" | awk '/files transferred/{print $NF}') if [[ "$files" != 0 ]]; then echo "Copied $files files" | ts '[%Y-%m-%d %H:%M:%S]' ./slackit.sh "$output" "$FOLDER_NAME File Transfer" fi fi fi