Fcron

(Scripts)
Line 99: Line 99:
=Scripts=
=Scripts=
-
So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and [[Phone control]] wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (chmod +x script.sh) to work.
+
So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and [[Phone control]] wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (chmod +x script.sh) to work. The second dbus call in some scripts is a notification and can me modified, removed or added.
===Silent profile===
===Silent profile===
Line 197: Line 197:
  fi
  fi
-
The second dbus call in some scripts is a notification and can me modified, removed or added.
+
===Tweakr profiles===
 +
 
 +
This script is not tested yet. Also you must replace both "tweakrprofile" instances with the name of your profile (which should not be general or silent and should not be capitalized).
 +
 
 +
#!/bin/sh
 +
 +
DBUSSET="dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:\'%s\' string:\'%s\'"
 +
 +
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
 +
 +
gconftool-2 -s /system/tweakr/current-preset --type=string "tweakrprofile"
 +
gconftool-2 -a /system/tweakr/tweakrprofile|sed 's/^ //'|sed 's/ = /=/'|awk -F'=' "{cmd=sprintf(\"${DBUSSET}\", \$1, \$2);system(cmd)}"
 +
 
[[Category:Software]]
[[Category:Software]]
[[Category:Power users]]
[[Category:Power users]]

Revision as of 17:45, 19 March 2010

Fcron is standard Linux scheduler used to schedule any command at any time. So this means that it doesn't have any limits and you can schedule just about anything. It is run as daemon in the background so you don't need to worry about it. You set it up with a config file which contains schedule.


Alternatives:


cron: Why not? - Cron is older than fcron and doesn't sleep between events.

anacron: Why not? - Anacron is used to schedule daily jobs, fcron can schedule to seconds.

ses: Why not? - Ses is buggy, buggy and buggy. It doesn't even uninstall properly.

Alarmed: It is the best alternative with a big plus (GUI), but also a big minus (no CLI). You can use custom command, so you can schedule anything, but you can't schedule it anytime (alarmed daemon doesn't provide an option for every possible time). It also needs python (because of the GUI, daemon itself doesn't need it), which consumes space.


Right now, fcron has to be:


- ported again so we have latest version and 100% compatibility (this one searches for vi in /scratchbox, so editor has to be defined manually each time fcrontab is run

- repacked, because a lot of stuff after the install has to be done manually - with proper packaging whole "Installation" chapter from this wiki would be unnecessary

- uploaded to official maemo.org repositories, so it can be used by anyone


But these are not major things and it can be used already, it's 100% stable, just needs some manual work.


Contents

Installation

Everything should be done from root terminal. First you need to download the .deb from ruskie's repository. Put it somewhere on the device and execute the following commands, one by one:

dpkg -i /path/to/deb/fcron_3.0.1-2_armel_opt.deb
apt-get install adduser
adduser fcron
rm -r /home/fcron
chown root:fcron /etc/fcron.*
chmod 644 /etc/fcron.*
chown -R fcron:fcron /var/spool/fcron
vi /etc/event.d/rcS-late

Last command opens rcS-late in vi text editor. You can use other text editor if you wish. After the line 38, which contains "initctl emit MOUNTS_OK" insert in a new line:

/etc/init.d/fcron start

Then save this file. Back in terminal execute the same line:

/etc/init.d/fcron start

Configuration

Fcrontab is a program which parses config file so fcron daemon can use it. It is used to modify schedule. From the root terminal first define the editor. This has to be done every time fcrontab is used.

export EDITOR=vi

Again, you can use another editor. Next, fcrontab must be executed in edit mode:

fcrontab -e

The config file opens and it is empty first time we open it. Now we will enter commands we would like to schedule. An example config file looks like:

!nolog(true)

# COMMENT
00 9 * * 1-5 run-standalone.sh /path/to/script/silent_profile.sh
<here are also other scripts>

!bootrun(true)
0 0 1 * * /path/to/script/reset_gprs_data_counter.sh

!nolog(true) is the first line and specifies that successful executions aren't logged (we really don't need or want that). Also, if we use a script with dbus call, run-standalone.sh must be in front of it. It sets up environment variables correctly for sending dbus calls as root. !bootrun(true) specifies that commands after this line are executed at next boot if system wasn't on when they should be executed. This is useful only for clearing the GPRS counter, for example if you switch the phone off every night the GPRS counter will still be reset every first of the month when you turn the phone on in the morning. That's why these two lines have to be at the end.


The first five fields are separated by a space:


[minute][SPACE][hour][SPACE][day_of_month][SPACE][month][SPACE][day_of_week][SPACE]/path/script.sh


To interpret the two example lines: GPRS data counter is reset every 1st of the month at 00:00. Silent profile is set every Monday to Friday at 9:00. Possible values for fields are:


minute: 0-59

hour: 0-23

day of month: 1-31

month: 1-12

day of week: 0-7 (0 and 7 are both Sunday)


Asterisk (*) means "any", or to put it differently: it means that this value does not define when the command is run.


After saving the edited config file, fcrontab will install it automatically and it will work from that moment on. Also don't forget that commenting out lines is useful for temporarily disabling a command. Just put an # in front of the line.

Scripts

So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and Phone control wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (chmod +x script.sh) to work. The second dbus call in some scripts is a notification and can me modified, removed or added.

Silent profile

#!/bin/sh
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"silent"
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Profile is set to Silent'

General profile

#!/bin/sh
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Profile is set to General'

Set radio mode to 2G

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Network mode is set to 2G'

Set radio mode to 3G

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Network mode is set to 3G'

Set radio mode to Dual

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:0
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Network mode is set to Dual'

Disconnect internet connection

#!/bin/sh
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Internet connection is disconnected'

Disconnect mobile network

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:false
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Mobile network is disconnected'

Connect mobile network

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:true
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Mobile network is connected'

Reset GPRS data counter

#!/bin/sh
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_rx_bytes
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_tx_bytes
gconftool-2 -s /system/osso/connectivity/network_type/GPRS/gprs_reset_time --type=string $(date +%s)

Lock phone

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_open string:'com.nokia.mce' string:'/com/nokia/mce/request' string:'com.nokia.mce.request' string:'devlock_callback' uint32:'3'

Unlock phone

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:'com.nokia.mce' string:'/com/nokia/mce/request' string:'com.nokia.mce.request' string:'devlock_callback' uint32:'0'

Reboot

#!/bin/sh
rootsh reboot

Auto 2G with WiFi

#!/bin/sh
#
# auto2g by J.LeFebvre
#
# Automatically sets 2G cellular mode when a valid WiFi connection is running
# This helps conserve battery life
#
# If an automatic connection to 3G is required when not on WiFi then uncomment the two dbus commands under "set to 3G" line
#
if `/sbin/ifconfig wlan0 2>/dev/null | grep -q RUNNING`; then
   if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 2'`; then
      if (/bin/ping -c 1 www.google.com > /dev/null); then
         # set to 2G
         dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
         dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'2G (GSM) cellular mode set'
      fi
   fi;
else
   if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 1'`; then
      # set to 3G
      # dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
      # dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'3G cellular mode set'
      echo  > /dev/null
   fi
fi

Tweakr profiles

This script is not tested yet. Also you must replace both "tweakrprofile" instances with the name of your profile (which should not be general or silent and should not be capitalized).

#!/bin/sh

DBUSSET="dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:\'%s\' string:\'%s\'"

dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"

gconftool-2 -s /system/tweakr/current-preset --type=string "tweakrprofile"
gconftool-2 -a /system/tweakr/tweakrprofile|sed 's/^ //'|sed 's/ = /=/'|awk -F'=' "{cmd=sprintf(\"${DBUSSET}\", \$1, \$2);system(cmd)}"
Retrieved from "http://wiki.maemo.org/Fcron"