mirror of
https://github.com/snachodog/handy-debian-scripts.git
synced 2025-04-26 21:12:23 -06:00
Adding move_recent.sh Script.
This script moves the most recent file in the current directory to a specified destination directory, and keeps a log of the moved files by timestamp. Only moves files that were added to the directory after the last timestamp.
This commit is contained in:
parent
c1bb99c8a5
commit
abf18918d9
35
move_recent.sh
Normal file
35
move_recent.sh
Normal file
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
SOURCE_DIR="/mnt/storage/Downloads"
|
||||
DEST_DIR="/home/steve/new_books"
|
||||
TIMESTAMP_FILE="/home/steve/.last_book_upload_time"
|
||||
|
||||
# Resolve full path of this script so we can exclude it
|
||||
SCRIPT_PATH="$(readlink -f "$0")"
|
||||
|
||||
# Ensure destination exists
|
||||
mkdir -p "$DEST_DIR"
|
||||
|
||||
# If no timestamp file exists, create one with a default time
|
||||
if [ ! -f "$TIMESTAMP_FILE" ]; then
|
||||
echo "First run. Creating timestamp file."
|
||||
date -d "1 day ago" +"%Y-%m-%d %H:%M:%S" > "$TIMESTAMP_FILE"
|
||||
fi
|
||||
|
||||
# Read the last run time
|
||||
LAST_RUN=$(cat "$TIMESTAMP_FILE")
|
||||
|
||||
echo "Syncing items modified since: $LAST_RUN"
|
||||
|
||||
# Find modified items (top-level only), excluding this script
|
||||
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -newermt "$LAST_RUN" -print0 |
|
||||
while IFS= read -r -d '' ITEM; do
|
||||
ITEM_PATH="$(readlink -f "$ITEM")"
|
||||
if [ "$ITEM_PATH" != "$SCRIPT_PATH" ]; then
|
||||
rsync -rP "$ITEM" "$DEST_DIR/"
|
||||
fi
|
||||
done
|
||||
|
||||
# Update timestamp after sync
|
||||
date +"%Y-%m-%d %H:%M:%S" > "$TIMESTAMP_FILE"
|
Loading…
x
Reference in New Issue
Block a user