Skip to content

Instantly share code, notes, and snippets.

@MorphyDK
Last active March 12, 2022 12:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MorphyDK/85790f42efb45190ddcc2e6b73c413d2 to your computer and use it in GitHub Desktop.
Save MorphyDK/85790f42efb45190ddcc2e6b73c413d2 to your computer and use it in GitHub Desktop.
Rclone mount check script - checks if your mount is connected, if not it will demount and reconnect.
#!/bin/bash
# 1. Change paths
# 2. for mount and log file & create mountchek file.
# 3. Add to crontab -e (paste the line bellow, without # in front)
# * * * * * /home/plex/scripts/rclone-mount-check.sh >/dev/null 2>&1
# Make script executable with: chmod a+x /home/plex/scripts/rclone-mount-check.sh
LOGFILE="/home/plex/logs/rclone-mount-check.log"
RCLONEREMOTE="Googlecrypt:"
MPOINT="/home/plex/mnt"
CHECKFILE="mountcheck.txt"
if pidof -o %PPID -x "rclone-mount-check.sh"; then
echo "$(date "+%d.%m.%Y %T") EXIT: Already running." | tee -a "$LOGFILE"
exit 1
fi
if [[ -f "$MPOINT/$CHECKFILE" ]]; then
echo "$(date "+%d.%m.%Y %T") INFO: Check successful, $MPOINT mounted." | tee -a "$LOGFILE"
exit
else
echo "$(date "+%d.%m.%Y %T") ERROR: $MPOINT not mounted, remount in progress." | tee -a "$LOGFILE"
# Unmount before remounting
while mount | grep "on ${MPOINT} type" > /dev/null
do
echo "($wi) Unmounting $mount"
fusermount -uz $MPOINT | tee -a "$LOGFILE"
cu=$(($cu + 1))
if [ "$cu" -ge 5 ];then
echo "$(date "+%d.%m.%Y %T") ERROR: Folder could not be unmounted exit" | tee -a "$LOGFILE"
exit 1
break
fi
sleep 1
done
rclone mount \
--allow-other \
--dir-cache-time 1000h \
--log-level INFO \
--log-file /plex/home/logs/rclone.log \
--poll-interval 15s \
--umask 002 \
--cache-dir=/home/plex/cache \
--vfs-cache-mode full \
--vfs-cache-max-size 150G \
--vfs-cache-max-age 48h \
--bwlimit-file 16M \
$RCLONEREMOTE $MPOINT &
while ! mount | grep "on ${MPOINT} type" > /dev/null
do
echo "($wi) Waiting for mount $mount"
c=$(($c + 1))
if [ "$c" -ge 4 ] ; then break ; fi
sleep 1
done
if [[ -f "$MPOINT/$CHECKFILE" ]]; then
echo "$(date "+%d.%m.%Y %T") INFO: Remount successful." | tee -a "$LOGFILE"
else
echo "$(date "+%d.%m.%Y %T") CRITICAL: Remount failed." | tee -a "$LOGFILE"
fi
fi
exit
@quadratz
Copy link

Missing \ at the end of line 47

@MorphyDK
Copy link
Author

MorphyDK commented Mar 12, 2022

Ahhh thanks :)

Minor typo, odd I didnt notice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment