Global scripts

Global scripts are run for every connection, both wired and wireless.

Simply place an executable script (actually, any executable file) in one of the subfolders in /etc/wicd/scripts.

The scripts are passed three parameters: whether the connection is wired or wireless, the ESSID (for wired networks this is just "wired" again) and the BSSID (wirelss) or profile name (wired) of the network.

For example, your script foo.sh might be called as

or

You can use the following as a base for your script:

#!/bin/bash

script="$(basename "$0")"
script_name="${script/.sh/}"

echo "Running ${script}" >"/var/log/wicd/${script_name}.log"
exec 2>>"/var/log/wicd/${script_name}.log"
exec 1>&2

connection_type="$1"
echo "Connection type: ${connection_type}"

if [ "${connection_type}" == "wired" ]; then
        profile="$3"
        echo "Profile: ${profile}"
elif [ "${connection_type}" == "wireless" ]; then
        essid="$2"
        bssid="$3"
        echo "ESSID: ${essid}"
        echo "BSSID: ${bssid}"
else
        echo "Unknown connection type: ${connection_type}" >&2
        exit
fi

Just add the code you want to run to the end, using the script variables $connection_type, $profile, $essid and $bssid.

Per-connection scripts

You can also assign scripts per-connection. For each connection, you can run up to one script just before connecting (pre-connect), one just after (post-connect), one just before disconnecting (pre-disconnect) and one just after disconnecting (post-disconnect).

You can do this by setting the beforescript, afterscript, predisconnectscript and postdisconnectscript entries in /etc/wicd/wireless-settings.conf and /etc/wicd/wired-settings.conf. You can also try to use wicd-gtk for this: in the network's settings page simply press the "Scripts" button.

On execution the are passed two arguments: BSSID and ESSID. Note that these are in reverse order to global scripts. If the network is wired the arguments will both simply be "wired". To see if wicd executes scripts you can run wicd on the foreground, for example by running 'wicd -f -o -e -a'. This requires root permissions.

Adding pre and post (dis)connection scripts (last edited 2011-06-29 18:24:54 by vzhost)