Active Topics

 



Notices


Reply
Thread Tools
Posts: 74 | Thanked: 25 times | Joined on Jan 2010 @ Hong Kong, CHINA
#451
Originally Posted by jgbreezer View Post
"[ $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.
 
Posts: 89 | Thanked: 52 times | Joined on Jan 2010 @ London, UK
#452
Originally Posted by hunludvig View Post
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.
Attached Files
File Type: txt alarmed_backend.py.patch.txt (1.7 KB, 85 views)

Last edited by jgbreezer; 2011-03-25 at 02:14.
 

The Following User Says Thank You to jgbreezer For This Useful Post:
geojoking's Avatar
Posts: 159 | Thanked: 53 times | Joined on Jan 2011 @ Romania, Cluj-Napoca
#453
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

Last edited by geojoking; 2011-04-11 at 17:42.
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#454
Originally Posted by geojoking View Post
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.

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.
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"?
 
Posts: 74 | Thanked: 25 times | Joined on Jan 2010 @ Hong Kong, CHINA
#455
Originally Posted by x-lette View Post
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.
 
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#456
Originally Posted by mdengler View Post
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


-________-
__________________
N900: One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.
 
Posts: 74 | Thanked: 25 times | Joined on Jan 2010 @ Hong Kong, CHINA
#457
Originally Posted by vi_ View Post
http://talk.maemo.org/showthread.php?t=68111


-________-

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?
 
Posts: 74 | Thanked: 25 times | Joined on Jan 2010 @ Hong Kong, CHINA
#458
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.
 
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#459
Originally Posted by mdengler View Post
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.
__________________
N900: One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.
 
geojoking's Avatar
Posts: 159 | Thanked: 53 times | Joined on Jan 2011 @ Romania, Cluj-Napoca
#460
Thanks for fixing the errors. But I still get this, when I run it:

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

Originally Posted by mdengler View Post
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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 01:56.