Last active
November 21, 2022 15:12
-
-
Save doob187/6cb8ed7939bf73b743242c1ebf22d7c0 to your computer and use it in GitHub Desktop.
move,sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### FUNCTIONS TO CHANGE ### | |
MIN_AGE=5 | |
SYNCPART="/folder/hier/Medien" | |
UNRAID_FOLDER="/folder/on/UNRAID" | |
IP="192.168.178.4" | |
REMOTE_PATH="SYNOFOLDER/" | |
SOURCE="//pfad/" | |
### RUNS SCRIPT ### | |
while true; do | |
### CHECK IS SYNO ONLINE ### | |
$(which ping) -c 1 -t 1 ${IP} > /dev/null 2> /dev/null | |
### ping and discard output | |
if [ $? -eq 0 ]; then | |
## check the exit code | |
## MOUNNT DRIVE VON SYNO ## | |
if [[ ! -d "${SYNCPART}" ]]; then | |
### $(which mount) "${SYNCPART}" | |
/usr/local/sbin/rc.unassigned mount "${SOURCE}" ### // SMB MOUNT COMMAND HERE ### | |
echo " ${SOURCE} " | |
sleep 10 | |
if [[ ! -d "${SYNCPART}" ]]; then echo " failed to mount folder " && exit 0 ; fi | |
fi | |
sleep 5 | |
### LIST FOLDERS and move ## | |
if [[ -d "${SYNCPART}" ]]; then | |
### RUNS TILL NOW ### | |
for folders in "${SYNCPART}"/* ; do | |
## MAPPING ALL FOLDERs BELOW ${SYNCPART}/* ## | |
mapfile -t files < <(eval find "${folders}" -type f -cmin +${MIN_AGE} ) | |
if [[ ${#files[@]} -gt 0 ]]; then | |
for i in "${files[@]}"; do | |
### CHECK FILE SIZE ### | |
while true; do | |
FILESIZE1=$(stat -c %s "${i}") | |
sleep 1 | |
FILESIZE2=$(stat -c %s "${i}") | |
sleep 1 | |
echo "${i}" | |
if [[ "$FILESIZE1" -ne "$FILESIZE2" ]]; then | |
echo " file size changed " && continue | |
elif [ "$FILESIZE1" -eq 0 ] || [ "$FILESIZE2" -eq 0 ]; then | |
echo "filesize is zero" && continue | |
else | |
echo "Filezize is the same" && break | |
fi | |
done | |
### RUN RSYNC ### | |
rsync "${folders}/${i}" "${UNRAID_FOLDER}/${i}" ####/// REST COMMAND HIER VON RSYNC /// | |
echo " ${i} is done " && sleep 5 | |
done | |
else | |
echo " not enough files found " | |
fi | |
done | |
else | |
echo " ${SYNCPART} is not mounted " | |
fi | |
## UNMOUNNT DRIVE VON SYNO ## | |
if [[ -d "${SYNCPART}" ]]; then | |
/usr/local/sbin/rc.unassigned umount "${SOURCE}" ### // SMB MOUNT COMMAND HERE ### | |
sleep 10 | |
if [[ -d "${SYNCPART}" ]]; then echo " failed to unmount folder " && exit 0 ; fi | |
fi | |
## SLEEPING 3600 SEC for nect loop ### | |
sleep 3600 | |
else | |
echo "${IP} is down" && sleep 60 && exit 0 | |
fi | |
done | |
### EMD OF FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment