Add move, copy and slackit
This commit is contained in:
parent
2f952bd9ee
commit
d4fa8509ae
4 changed files with 126 additions and 1 deletions
|
@ -4,4 +4,5 @@ A collection of useful scripts that I use everyday
|
|||
|
||||
- getStarred.sh - Get starred articles from Miniflux and copy to clipboard. [Notes](https://www.alexhyett.com/notes/getting-starred-items-from-miniflux/)
|
||||
- unstar.sh - Unstar all starred articles on Miniflux. [Notes](https://www.alexhyett.com/notes/getting-starred-items-from-miniflux/)
|
||||
- syncBlog.sh - The script I use to sync my notes and articles from Obsidian to my website. Converting the links. [Notes](https://www.alexhyett.com/notes/syncing-my-obsidian-notes-with-my-blog/)
|
||||
- syncBlog.sh - The script I use to sync my notes and articles from Obsidian to my website. Converting the links. [Notes](https://www.alexhyett.com/notes/syncing-my-obsidian-notes-with-my-blog/)
|
||||
- moveFiles.sh - This script checks to see if my server (friday) is online and the folders are mounted before moving files downloaded using rsync.
|
51
copyFiles.sh
Executable file
51
copyFiles.sh
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/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 <downloads_path> --mount <mount_path>"
|
||||
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
|
60
moveFiles.sh
Executable file
60
moveFiles.sh
Executable file
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
cd "$parent_path"
|
||||
|
||||
SERVER_IP=friday
|
||||
DOWNLOADS=""
|
||||
MOUNT=""
|
||||
DELETE_EMPTY=false
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--downloads)
|
||||
DOWNLOADS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--mount)
|
||||
MOUNT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--delete-empty)
|
||||
DELETE_EMPTY=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$DOWNLOADS" ] || [ -z "$MOUNT" ]; then
|
||||
echo "Usage: $0 --downloads <downloads_path> --mount <mount_path> [--delete-empty]"
|
||||
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. Moving files." | ts '[%Y-%m-%d %H:%M:%S]'
|
||||
files=$(ls "$MOUNT") # Trigger drive spin up
|
||||
sleep 5
|
||||
|
||||
output=$(rsync -avzh --remove-source-files --stats --exclude '.gitkeep' "$DOWNLOADS" "$MOUNT" | grep -A 1 'files transferred')
|
||||
files=$(echo "$output" | awk '/files transferred/{print $NF}')
|
||||
|
||||
if [ "$DELETE_EMPTY" = true ]; then
|
||||
find "$DOWNLOADS" -type d -empty -delete
|
||||
fi
|
||||
|
||||
if [[ "$files" != 0 ]]; then
|
||||
echo "Transferred $files files" | ts '[%Y-%m-%d %H:%M:%S]'
|
||||
./slackit.sh "$output" "$FOLDER_NAME File Transfer"
|
||||
fi
|
||||
fi
|
||||
fi
|
13
slackit.sh
Executable file
13
slackit.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash -e
|
||||
message=$(echo $1 | tr -d '\n' | tr -d '"')
|
||||
username=$(echo $2 | tr -d '\n' | tr -d '"')
|
||||
|
||||
SLACK_URL=https://hooks.slack.com/services/SDS9SDID9D9SJS9SDS
|
||||
|
||||
if [ -z "$username" ]; then
|
||||
username="Server"
|
||||
fi
|
||||
|
||||
if [ ! -z "$message" ]; then
|
||||
curl -X POST -H 'Content-type: application/json' --data "{ \"channel\": \"#notifications\", \"username\": \"${username}\", \"icon_emoji\": \":bot:\", \"text\": \"${message}\" }" $SLACK_URL
|
||||
fi
|
Loading…
Reference in a new issue