Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I wrote a script in "/etc/NetworkManager/dispatcher.d" to open the Firefox preferences dialog whenever I connect to a particular network (college wifi), because I have to enable proxy.

The script is returning with "error code 1" in the logger. If I comment out the "firefox --preferences" line, the script runs and the "FIREFOX SCRIPT EXECUTED" text is displayed in the logger. How do I rectify it? Here's the script:

#!/bin/sh -e

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2 
    exit 1;
fi


case "$2" in
    up|vpn-up)
    if [ "$CONNECTION_UUID" = "6e7f613f-5563-48f7-892d-655e95c0b834" ]; then
        firefox -preferences
        logger -s "FIREFOX SCRIPT EXECUTED"
    fi
    ;;
   down|vpn-down)
    ;;
   hostname)
   # Do nothing
   exit 0
       ;;
   hostname|dhcp4-change|dhcp6-change)
       # Do nothing
   ;;
   *)
    echo "$0: called with unknown action \`$2'" 1>&2
    exit 1
    ;;
esac
share|improve this question

1 Answer 1

up vote 0 down vote accepted

First problem is that the call of firefox --preferences stops the script. Second problem is the script is executed as root not as the logged in user. Third: Firefox needs the users environment as well as the display number.

Change the "up"-part in the script as follows:

case "$2" in
    up|vpn-up)
    if [ "$CONNECTION_UUID" = "6e7f613f-5563-48f7-892d-655e95c0b834" ]; then
        export HOME=/home/user
        export DISPLAY=:0
        nohup sudo -u user firefox --preferences &
        logger -s "FIREFOX SCRIPT EXECUTED"
    fi
    ;;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.