Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Bash script to move files when drive >xx% until <xx%

Featured Replies

I'm trying to get a script to transfer files from my cache to the remote mount, this should be triggered when the cache is >70% and then transfer files until cache is <70%.

I'm not very knowledgeable when it comes to this stuff so I've come up with this by studying others work on the mighty interwebs.

Below transfers 1 file and then the script completes.

Spoiler
#!/bin/bash

Local='/mnt/cache/lokalt/'
Remote='/mnt/remotes/Gdrive/Lagring/'
ExcludeDir1=rutorrent
ExcludeDir2=nzbget
CacheDrive='/mnt/cache'
Percent='70'

df -h | grep $CacheDrive | awk '{ print $5 }' | cut -d'%' -f1 | while read FSC; do
	if [ $FSC -ge $Percent ]; then
		find $Local -ctime +0 -type f -not -path $Local$ExcludeDir1'/*' -not -path $Local$ExcludeDir2'/*' -printf '%T@ %p\n' | sort -k1,1 -g | head -1 | sed 's/^[0-9.]\+ //' | cut -d'/' -f5,6,7,8,9 | while read OldestFile; do
		rclone move $Local"$OldestFile" $Remote"$OldestFile" --dry-run --progress --size-only --exclude .unionfs/** --exclude *fuse_hidden* --exclude *_HIDDEN --exclude .recycle** --exclude *.backup~* --exclude *.partial~* --exclude *.partial* --exclude *.Partial~* --exclude *.Partial* --delete-after --delete-empty-src-dirs
	done
fi
done

 

And this loops the script, but it continues even after the cache drive utilization is below 70%. I suspect that the mistake I've made is that the first string with "df -h ...." is stale and that the subsequent commands is using the initial value all the time?

Spoiler
#!/bin/bash

Local='/mnt/cache/lokalt/'
Remote='/mnt/remotes/Gdrive/Lagring/'
ExcludeDir1=rutorrent
ExcludeDir2=nzbget
CacheDrive='/mnt/cache'
Percent='70'

df -h | grep $CacheDrive | awk '{ print $5 }' | cut -d'%' -f1 | while read FSC; do
	while [ $FSC -ge $Percent ]; do
		find $Local -ctime +0 -type f -not -path $Local$ExcludeDir1'/*' -not -path $Local$ExcludeDir2'/*' -printf '%T@ %p\n' | sort -k1,1 -g | head -1 | sed 's/^[0-9.]\+ //' | cut -d'/' -f5,6,7,8,9 | while read OldestFile; do
		rclone move $Local"$OldestFile" $Remote"$OldestFile" --dry-run --progress --size-only --exclude .unionfs/** --exclude *fuse_hidden* --exclude *_HIDDEN --exclude .recycle** --exclude *.backup~* --exclude *.partial~* --exclude *.partial* --exclude *.Partial~* --exclude *.Partial* --delete-after --delete-empty-src-dirs --log-level INFO
		done
	done
done

 

Can anyone help me get this script working as I intend?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.