Hey there.
I sometimes leave my computer at night uploading files to an FTP server. It sometimes needs to upload just 300MB, sometimes 3GB.
In Lion, I had no problems at all. I started uploading, turned screen off (Shift+Control+Eject that is) and went to sleep. The Mini would keep uploading till done, and then would go to sleep too.
In Mountain Lion well, can't really do that anymore. If I start uploading something and then turn the screen off, the Mini will go to sleep in a 1 minute to 5 minutes bracket, no matter what. (Sleep is set to 12 minutes, so weird And I don't wanna disable it as I like it to go sleep when not in use).
I then read about caffeinate, and tried estimating how long it'd take to upload all the files and ran:
That keeps my computer awake for 2 hours and then puts it to sleep. So pretty nice.
I then decided to create a program which would monitor the upload speed and put the Mini to sleep as soon as it's done.
Problem is it isn't working. I mean, the program works but it's like if no caffeinate process was executed. Can't figure out why.
Any help?
Here's the code:
Idea: See average upload speed in 5 seconds. If higher than 50KB/s, caffeinate the computer for 5 minutes. Check again. As soon as it's lower, it'll start a 5 minute wait devided in 5 to check if the speed drop was puntual.
If upload speed is lower than 50KB/s for 5 minutes, then program quits and computer is free to go to sleep as soon as it wants to.
As I said though, it isn't working.
I sometimes leave my computer at night uploading files to an FTP server. It sometimes needs to upload just 300MB, sometimes 3GB.
In Lion, I had no problems at all. I started uploading, turned screen off (Shift+Control+Eject that is) and went to sleep. The Mini would keep uploading till done, and then would go to sleep too.
In Mountain Lion well, can't really do that anymore. If I start uploading something and then turn the screen off, the Mini will go to sleep in a 1 minute to 5 minutes bracket, no matter what. (Sleep is set to 12 minutes, so weird And I don't wanna disable it as I like it to go sleep when not in use).
I then read about caffeinate, and tried estimating how long it'd take to upload all the files and ran:
Code:
$ caffeinate -t 7200
That keeps my computer awake for 2 hours and then puts it to sleep. So pretty nice.
I then decided to create a program which would monitor the upload speed and put the Mini to sleep as soon as it's done.
Problem is it isn't working. I mean, the program works but it's like if no caffeinate process was executed. Can't figure out why.
Any help?
Here's the code:
Code:
coffee(){
count=0
while [ $count -lt 5 ]
do
a=`netstat -ibI en1 | awk '$3 ~ /Link/ {print $10}'`
sleep 5
b=`netstat -ibI en1 | awk '$3 ~ /Link/ {print $10}'`
in=$(((b-a)/1024/5))
if [ $in -gt 50 ]
then echo "Downloading at $in KB/s"
echo "Waiting 5 minutes..."
echo ""
count=0
caffeinate -t 300
else
count=$((count+1))
echo "Wait $count of 5... (1 minute)"
echo ""
caffeinate -t 60
fi
done
echo ""
echo "LET'S SLEEP"
echo ""
}
Idea: See average upload speed in 5 seconds. If higher than 50KB/s, caffeinate the computer for 5 minutes. Check again. As soon as it's lower, it'll start a 5 minute wait devided in 5 to check if the speed drop was puntual.
If upload speed is lower than 50KB/s for 5 minutes, then program quits and computer is free to go to sleep as soon as it wants to.
As I said though, it isn't working.
Last edited: