View Single Post
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#1
Smart mail checking alarmd script

This is a fairly simple script that will sync your email. It can be set to run hourly etc. with crom/alarmd etc.

The thng that makes this script special is that it will put your wifi back to the way it is when it is run.

For example there are 3 possibilities. 1. wifi is already connected, 2 wifi kernel modules loaded, kernel modules not loaded. This script will detect one of the three possibilities, take appropriate action (load modules, connect etc) then return your wifi back to it's original setting (unloaded, not connect, connected).

It can be run with:

Code:
echo "/path/to/script.sh" | sudo gainroot | echo ""
and the script:

Code:
#!/bin/sh
#smart email check script
out=`ifconfig wlan0`
if [ $? -eq "0" ] ; then
	if [ `echo "$out" | grep -c RUNNING` -gt "0" ] ; then
		echo "wifi connected, checking mail"
		run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive

	else
		echo "wifi disconnected, connecting..."
		sleep 2
		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 15
		run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
		echo "checking mail"
		sleep 55
		dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true | echo ""
	fi	
	exit 2

	else
		echo "wifi modules unloaded, bringing up"
		modprobe wl12xx
                wl1251-cal
                stop wlancond
                start wlancond
                ifconfig wlan0 up

		sleep 1
		dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0 | echo ""
		sleep 7
		run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
		echo "checking email"
		sleep 35
		ifconfig wlan0 down
                rmmod wl12xx

	exit 0
fi
unfortunatley you need to have modest 'autoupdate' enabled for it to respond to the syncemail dbus call (which totally sucks btw). I have simply editited the modest.conf autocheck time value to 999999.

Seems to work!
 

The Following 3 Users Say Thank You to vi_ For This Useful Post: