Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a system with Ubuntu installed in 20GB and windows in 100 GB, two partitions - each of 100GB using NTFS. While using DC++ (multiple downloading of big file) I used to get message that system is running out of memory.

Is there any way to make a deamon which will be checking the Ubuntu partition so that if its used space goes up to a certain amount (let's say 18 GB) it will automatically start a moving file from this drive to another drive (let's assume it will pick the file from movie folder or largest media file from this drive to move)?

Or it prompt to ask from user which file to move?

Is there any program which can do this for me? If not, can you suggest something to read so that I could make it?

share|improve this question
2  
Why don't you make dc++ download directly to one of your 100gb NTFS partitions? –  Karthik Dec 10 '12 at 20:05
add comment

1 Answer

up vote 4 down vote accepted

Why don't you just point DC++ to save to another drive by default instead of constantly moving files around?

A solution similar to what you have asked for:

#!/bin/bash

srcPart="sda9"
dstDir="/media/drive/dir"

moveLargestFile(){
    largestFile="`ls -S -w1 "$1"/*.avi | head -n 1`"
    mv "$largestFile" "$dstDir"
}

your-app &
appPid=$!

while [ "`ps -A | grep $appPid`" ]; do
    usePercent=$(df -h | grep "$srcPart" | grep -o "[0-9]\{1,3\}%" | sed 's/%//')
    if [ $usePercent -gt 95 ]; then
        moveLargestFile "$HOME/Movies"
    fi
    sleep 60
done

This sript will launch your app (don't forget to specify it) in the background and will monitor the selected partition srcPart until you quit the application. If during its executing, filesystem usage goes over 95%, we'll select the largest avi file in $HOME/Movies folder and move it to the specified location.

share|improve this answer
    
Welcome to Ask Ubuntu! This is a great answer, keep it up. We can't wait to see you here more frequently in our community :) –  Mochan Dec 10 '12 at 21:29
1  
Thanks :) It is indeed my first post here. –  Pavel A Dec 10 '12 at 21:55
1  
thanks man .. small and perfect solution.. :) –  RATHI Dec 11 '12 at 4:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.