perjantai 18. kesäkuuta 2010

E-mail sync at low load

N900's default e-mail client Modest is a pretty heavy app when doing syncing, not nice if you're in the middle of trying to get something done. Luckily about anything can be scripted in the N900 so here's a script that syncs only when CPU load below the defined level. It also stores the time of last (try of) syncing and syncs only if a defined time has passed.

Run this every 1 minute (or whatever) with Alarmed. Seems to sync all e-mail accounts.


#!/bin/sh

secsbetween=600 #Only run if 10 minutes has passed since last update
maxload=40 #Only run if 5 min average load less than 0.40

if [ -s /tmp/prevmail.tmp ]
then prev=`cat /tmp/prevmail.tmp`
else prev=0
fi
cur=`date +%s`
if [ $(( $cur - $secsbetween)) -gt $prev ]; then
echo Time passed
load=`uptime|cut -d "," -f 4|tr -d " ."`
echo Load $load

if [ $load -lt $maxload ] ; then
echo Load low enough

#Uncomment to display a message when updating
# run-standalone.sh dbus-send --type=method_call\
--dest=org.freedesktop.Notifications\
/org/freedesktop/Notifications\
org.freedesktop.Notifications.SystemNoteInfoprint\
string:"Updating e-mail..."
#Make sure connection is open
run-standalone.sh dbus-send --system --type=method_call\
--dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect\
string:"[ANY]" uint32:0
sleep 10
#Sync
run-standalone.sh dbus-send --type=method_call\
--dest=com.nokia.asdbus /com/nokia/asdbus\
com.nokia.asdbus.syncEmail
date
date +%s > /tmp/prevmail.tmp
fi
fi

Ei kommentteja:

Lähetä kommentti