Skip to content

Instantly share code, notes, and snippets.

@AloiSama
Last active April 23, 2017 17:05
Show Gist options
  • Select an option

  • Save AloiSama/a30282933f3bb5081ebe9ceedb91776d to your computer and use it in GitHub Desktop.

Select an option

Save AloiSama/a30282933f3bb5081ebe9ceedb91776d to your computer and use it in GitHub Desktop.

Revisions

  1. AloiSama revised this gist Apr 23, 2017. 4 changed files with 50 additions and 42 deletions.
    28 changes: 14 additions & 14 deletions fuse-mount.cron
    Original file line number Diff line number Diff line change
    @@ -7,23 +7,23 @@
    logfile="/home/scripts/logs/fuse-mount.cron.log"

    if pidof -o %PPID -x "fuse-mount.cron"; then
    echo "$(date "+%d.%m.%Y %T") EXIT: fuse-mount.cron already running."
    exit 1
    echo "$(date "+%d.%m.%Y %T") EXIT: fuse-mount.cron already running."
    exit 1
    fi

    if [[ -f "/home/tv/mountcheck" ]]; then
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, fuse mounted." | tee -a "$logfile"
    exit
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, fuse mounted." | tee -a "$logfile"
    exit
    else
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/tv | tee -a "$logfile"
    /usr/bin/unionfs-fuse -o cow,allow_other,nonempty /home/plex-tv-r=RW:/home/gd-tv=RO /home/tv
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/tv | tee -a "$logfile"
    /usr/bin/unionfs-fuse -o cow,allow_other,nonempty /home/plex-tv-r=RW:/home/gd-tv=RO /home/tv

    if [[ -f "/home/tv/mountcheck" ]]; 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
    if [[ -f "/home/tv/mountcheck" ]]; 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
    exit
    8 changes: 8 additions & 0 deletions ls -l scripts directory
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    hostname:/home/scripts# ls -l
    total --K
    -rwxr-xr-x 1 root root 1.1K Apr 16 02:30 fuse-mount.cron
    drwxr-xr-x 2 root root 4.0K Apr 17 02:43 logs
    -rwxr-xr-x 1 root root 1.2K Apr 23 10:53 mount-m.cron
    -rwxr-xr-x 1 root root 1.2K Apr 16 02:04 mount-tv.cron
    -rwxr-xr-x 1 root root 721 Apr 23 10:59 upload-m.cron
    -rwxr-xr-x 1 root root 716 Apr 23 10:59 upload-tv.cron
    44 changes: 22 additions & 22 deletions mount-tv.cron
    Original file line number Diff line number Diff line change
    @@ -7,31 +7,31 @@
    logfile="/home/scripts/logs/mount-tv.cron.log"

    if pidof -o %PPID -x "mount-tv.cron"; then
    echo "$(date "+%d.%m.%Y %T") EXIT: mount-tv.cron already running."
    exit 1
    echo "$(date "+%d.%m.%Y %T") EXIT: mount-tv.cron already running."
    exit 1
    fi

    if [[ -f "/home/gd-tv/mountcheck" ]]; then
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, gd-tv mounted." | tee -a "$logfile"
    exit
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, gd-tv mounted." | tee -a "$logfile"
    exit
    else
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/gd-tv | tee -a "$logfile"
    rclone mount \
    --read-only \
    --allow-non-empty \
    --allow-other \
    --max-read-ahead 200M \
    --checkers 16 \
    --quiet \
    --stats 0 \
    egdtv:/LIBRARY/TV /home/gd-tv/&
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/gd-tv | tee -a "$logfile"
    rclone mount \
    --read-only \
    --allow-non-empty \
    --allow-other \
    --max-read-ahead 200M \
    --checkers 16 \
    --quiet \
    --stats 0 \
    egdtv:/LIBRARY/TV /home/gd-tv/&

    if [[ -f "/home/gd-tv/mountcheck" ]]; 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
    if [[ -f "/home/gd-tv/mountcheck" ]]; 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
    12 changes: 6 additions & 6 deletions upload-tv.cron
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,19 @@
    # * * * * * root /home/scripts/upload-tv.cron >/dev/null 2>&1

    if pidof -o %PPID -x "upload-tv.cron"; then
    exit 1
    exit 1
    fi

    LOGFILE="/home/scripts/logs/upload-tv.cron.log"
    LOGFILE="/home/scripts/logs/upload-tv.cron"
    FROM="/home/plex-tv-r/"
    TO="egd1:/LIBRARY/TV"

    # CHECK FOR FILES IN FROM FOLDER THAT ARE OLDER THEN 15 MINUTES
    if find $FROM* -type f -mmin +15 | read
    then
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD STARTED" | tee -a $LOGFILE
    # MOVE FILES OLDER THEN 15 MINUTES
    rclone move $FROM $TO -c --no-traverse --transfers=10 --checkers=10 --delete-after --min-age 15m --log-file=$LOGFILE
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD ENDED" | tee -a $LOGFILE
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD STARTED" | tee -a "$LOGFILE"
    # MOVE FILES OLDER THEN 15 MINUTES
    rclone move $FROM $TO -c --no-traverse --transfers=10 --checkers=10 --delete-after --min-age 15m --log-file="$LOGFILE"
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD ENDED" | tee -a "$LOGFILE"
    fi
    exit
  2. AloiSama revised this gist Apr 23, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upload-tv.cron
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ if pidof -o %PPID -x "upload-tv.cron"; then
    exit 1
    fi

    LOGFILE="/home/scripts/logs/upload-tv.cron"
    LOGFILE="/home/scripts/logs/upload-tv.cron.log"
    FROM="/home/plex-tv-r/"
    TO="egd1:/LIBRARY/TV"

  3. AloiSama created this gist Apr 23, 2017.
    29 changes: 29 additions & 0 deletions fuse-mount.cron
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash
    # Change paths for mount and log file & create mountcheck file.
    # Add script to crontab by typing crontab -e and pasting the line below (without # in front )
    # * * * * * /home/scripts/fuse-mount.cron >/dev/null 2>&1
    # Make script executable with: chmod a+x /home/scripts/fuse-mount.cron

    logfile="/home/scripts/logs/fuse-mount.cron.log"

    if pidof -o %PPID -x "fuse-mount.cron"; then
    echo "$(date "+%d.%m.%Y %T") EXIT: fuse-mount.cron already running."
    exit 1
    fi

    if [[ -f "/home/tv/mountcheck" ]]; then
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, fuse mounted." | tee -a "$logfile"
    exit
    else
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/tv | tee -a "$logfile"
    /usr/bin/unionfs-fuse -o cow,allow_other,nonempty /home/plex-tv-r=RW:/home/gd-tv=RO /home/tv

    if [[ -f "/home/tv/mountcheck" ]]; 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
    37 changes: 37 additions & 0 deletions mount-tv.cron
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash
    # Change paths for mount and log file & create mountcheck file.
    # Add script to crontab by typing crontab -e and pasting the line below (without # in front )
    # * * * * * /home/plex/scripts/mount.cron >/dev/null 2>&1
    # Make script executable with: chmod a+x /home/scripts/mount.cron

    logfile="/home/scripts/logs/mount-tv.cron.log"

    if pidof -o %PPID -x "mount-tv.cron"; then
    echo "$(date "+%d.%m.%Y %T") EXIT: mount-tv.cron already running."
    exit 1
    fi

    if [[ -f "/home/gd-tv/mountcheck" ]]; then
    echo "$(date "+%d.%m.%Y %T") INFO: Check successful, gd-tv mounted." | tee -a "$logfile"
    exit
    else
    echo "$(date "+%d.%m.%Y %T") ERROR: Drive not mounted, remount in progress." | tee -a "$logfile"
    # Unmount before remounting
    fusermount -uz /home/gd-tv | tee -a "$logfile"
    rclone mount \
    --read-only \
    --allow-non-empty \
    --allow-other \
    --max-read-ahead 200M \
    --checkers 16 \
    --quiet \
    --stats 0 \
    egdtv:/LIBRARY/TV /home/gd-tv/&

    if [[ -f "/home/gd-tv/mountcheck" ]]; 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
    22 changes: 22 additions & 0 deletions upload-tv.cron
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash
    # RCLONE UPLOAD CRON TAB SCRIPT
    # Type crontab -e and add line below (without # )
    # * * * * * root /home/scripts/upload-tv.cron >/dev/null 2>&1

    if pidof -o %PPID -x "upload-tv.cron"; then
    exit 1
    fi

    LOGFILE="/home/scripts/logs/upload-tv.cron"
    FROM="/home/plex-tv-r/"
    TO="egd1:/LIBRARY/TV"

    # CHECK FOR FILES IN FROM FOLDER THAT ARE OLDER THEN 15 MINUTES
    if find $FROM* -type f -mmin +15 | read
    then
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD STARTED" | tee -a $LOGFILE
    # MOVE FILES OLDER THEN 15 MINUTES
    rclone move $FROM $TO -c --no-traverse --transfers=10 --checkers=10 --delete-after --min-age 15m --log-file=$LOGFILE
    echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD ENDED" | tee -a $LOGFILE
    fi
    exit