maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting) (https://talk.maemo.org/showthread.php?t=46594)

mdengler 2011-03-19 15:38

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by jgbreezer (Post 970426)
"[ $checklate -gt 21 -a $checklate -lt 5 ] && ( exit 1 )" (note the extra brackets) will never exit the script early - do who knows why?

exit 1 just exits the subshell you put it in with the parentheses.

jgbreezer 2011-03-25 02:09

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
1 Attachment(s)
Quote:

Originally Posted by hunludvig (Post 950371)
Hi Jgbreezer,
I didn't know this usage of function range(), it perfectly substitutes the code I wrote, please create a patch and post it here to be merged in the next version.

Hi, been a while since I said I would (exactly a month since, when I started this draft, but chrome has been restarted even a couple of times since then with the same reply-to-thread page open with this text - love how it keeps page form content as well as the tabs between restarts), but finally got round to creating that patch with the range(m,y,step) improvements - if you didn't already put anything in for this.. :)

I realised that the "range(0,11,n)" isn't /quite/ exactly the same as "range(1,12) if not i%n" as I said it was, but the new edit is how regular vixie cron actually works. This will change the behaviour slightly to use different offsets past the minute/hour/..., but still run jobs with the same gaps between overall (except perhaps the last one of a range to the next time it runs).. I also realised that with range(1,12) there's a bug as it will never be 12. range() stops before it gets to the 'end' value, its like the .end() of a c++ iterator if that means anything to you, ie. its not a value the iterator has that is real data it loops with. If you ask for range(12) you get all the values from 0 through 11 inclusive - 12 different values. Surely you (the python guys) knew this...

So it needs to be range(1,13). Shoulda seen that before too. Original poster of these edits didn't test for stuff like this! The existing code will also never run at 59mins past, or the last hour of the day, or last day of the week or any last-anything'th of a range because the range is too small at the far end. Fixed in the attached patch..

I also considered including code to support the "/n" suffix for ranges rather than just "*/2" for instance, so that I could get "4-9/2" to run at 4,6,8; and could refactor the code that handles all this range stuff into one function or lambda for easier maintainability (and just pass in the range default start/end values and the string used for that value's entry), but that's for another time. If I get to it ever.

Anyway, enjoy the fixes and code improvements.

geojoking 2011-04-11 17:26

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
I'm trying to add this script for E-mail sync to Alarmed but I can't seem to make it work. It's set to sync mail and then disconnect from the Internet (if GPRS).

Also, I think the script itself has some problems because if I run it in terminal I get several "if" bugs and "sleep 100" and "sleep 10" erors.

Code:

#!/bin/sh
if [ `route | awk '/au/ {print $1}'` = default ]; then
exit
else
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
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
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
sleep 100
  if [ `ifconfig gprs0 | awk -F " " '/s0/ {print $2}'` = Link ]; then
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  fi
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"E-mail updated"
fi


x-lette 2011-04-12 10:39

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by geojoking (Post 985757)
Also, I think the script itself has some problems because if I run it in terminal I get several "if" bugs and "sleep 100" and "sleep 10" erors.

First you should make sure the script is working correctly before trying to use it with some automated trigger like alarmed. In worst case you could shred your device this way if the script runs wild and gets started over and over again.

Then you should append the actual error messages to your post so one could help you on the point instead of guessing. Therefore all following hints are just guessed and might be wrong too. ;)

Quote:

Code:

#!/bin/sh
if [ `route | awk '/au/ {print $1}'` = default ]; then


Error #1: You are using an assignement instead of an equality testing operator just as if you'd try to assign the value "default" to the variable " `route | awk '/au/ {print $1}'` ". You should instead use '==' to test equality of output and string.
Error #2: all strings have to be enclosed by quotation marks. All not-enclosed values are treated as numbers which will obviously fail in this case.
Quote:

Code:

if [ `ifconfig gprs0 | awk -F " " '/s0/ {print $2}'` = Link ]; then

Same as above.

What errors do you get concerning "sleep" command? Something like "command not found"?

mdengler 2011-04-12 14:43

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by x-lette (Post 986341)
First you should make sure the script is working correctly before trying to use it with some automated trigger like alarmed. In worst case you could shred your device this way if the script runs wild and gets started over and over again.

Then you should append the actual error messages to your post so one could help you on the point instead of guessing. Therefore all following hints are just guessed and might be wrong too. ;)

What you said.

Furthermore, here is an improved version of that script:

Code:

#!/bin/sh
#
# n900 / maemo script
#
# Function: trigger an email fetch; connect to the internet if possible & necessary
#
# Copyright: 2011 Martin Dengler <martin@martindengler.com>
# Dual License: MIT / GPL v3+

retrys=5

while [ $retrys -gt 0 ] ; do
    if /sbin/route | grep -q "^default " ; then
        break  #...we are connected
    else
        run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd --print-reply /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
        retrys=`expr $retrys - 1`
        sleep 5
    fi
done

/sbin/route | grep -q "^default " || exit 1

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive

sleep 120

# if we connected just for this, disconnect
if [ $retrys -lt 5 ]; then
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi

I have tested it and seems to work fine.

I removed the last "Email updated" because that's basically a lie (since we don't know that modest received that dbus message - see https://bugs.maemo.org/show_bug.cgi?id=7834 ), and I can't see the point of blindly sending such a message after just waiting two minutes.

vi_ 2011-04-12 14:45

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by mdengler (Post 986511)
What you said.

Furthermore, here is an improved version of that script:

Code:

#!/bin/sh
#
# n900 / maemo script
#
# Function: trigger an email fetch; connect to the internet if possible & necessary
#
# Copyright: 2011 Martin Dengler <martin@martindengler.com>
# Dual License: MIT / GPL v3+

retrys=5

while [ $retrys -gt 0 ] ; do
    if /sbin/route | grep -q "^default " ; then
        break  #...we are connected
    else
        run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd --print-reply /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
        retrys=`expr $retrys - 1`
        sleep 5
    fi
done

/sbin/route | grep -q "^default " || exit 1

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive

sleep 120

# if we connected just for this, disconnect
if [ $retrys -lt 5 ]; then
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi

I have tested it and seems to work fine.

I removed the last "Email updated" because that's basically a lie (since we don't know that modest received that dbus message - see https://bugs.maemo.org/show_bug.cgi?id=7834 ), and I can't see the point of blindly sending such a message after just waiting two minutes.


http://talk.maemo.org/showthread.php?t=68111


-________-

mdengler 2011-04-12 15:01

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by vi_ (Post 986513)


I like your last comment in that thread (perhaps a bit unfair but amusing)

I don't understand why you handle the case where the wifi modules are unloaded - does that happen often?

mdengler 2011-04-12 15:03

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Also, do you think the dbus method actually works? There is some evidence ( https://bugs.maemo.org/show_bug.cgi?id=7834 ) that it might not.

vi_ 2011-04-12 15:09

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by mdengler (Post 986536)
Also, do you think the dbus method actually works? There is some evidence ( https://bugs.maemo.org/show_bug.cgi?id=7834 ) that it might not.

A while back it was popular to use 'wifi switcher' to unload the wifi modules, this fixed a bug where it would drain power in the background when you wern't connected to wifi (or somthing like that).

The dbus method for checking email send/receive does work, you just have to have modest autocheck enabled (in modest options). To stop modest autocheck from interferring with alarmed email check, I found you could enable autocheck and set autocheck interval 1 year (or somthing as equally outlandish) via a gconf setting.

geojoking 2011-04-13 07:33

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Thanks for fixing the errors. But I still get this, when I run it:

line 32: syntax error: "fi" unexpected (expecting "then")

Quote:

Originally Posted by mdengler (Post 986511)
What you said.

Furthermore, here is an improved version of that script:

Code:

#!/bin/sh
#
# n900 / maemo script
#
# Function: trigger an email fetch; connect to the internet if possible & necessary
#
# Copyright: 2011 Martin Dengler <martin@martindengler.com>
# Dual License: MIT / GPL v3+

retrys=5

while [ $retrys -gt 0 ] ; do
    if /sbin/route | grep -q "^default " ; then
        break  #...we are connected
    else
        run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd --print-reply /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
        retrys=`expr $retrys - 1`
        sleep 5
    fi
done

/sbin/route | grep -q "^default " || exit 1

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive

sleep 120

# if we connected just for this, disconnect
if [ $retrys -lt 5 ]; then
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi

I have tested it and seems to work fine.

I removed the last "Email updated" because that's basically a lie (since we don't know that modest received that dbus message - see https://bugs.maemo.org/show_bug.cgi?id=7834 ), and I can't see the point of blindly sending such a message after just waiting two minutes.



All times are GMT. The time now is 07:31.

vBulletin® Version 3.8.8