1

I want to execute a script that starts synergy whenever my laptop wifi cards hooks up to a network (for now any, i'll add a filter later). So I wrote a script `/etc/network/if-up.d/999startsynergy' that looks like:

#!/bin/bash
########################################################################
# script to start synergy 
# for remote mouse & keyboard control
# from my Desktop PC & work laptop
# script by: Ron Eggler 11/05/2016
#
########################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# Configuration:
#
host1='DesktopHome'
host2='GEnotebook'
bin='/usr/bin/synergyc'

case $1 in
        up)
        sleep 5
        $bin $host1
        $bin $host2
        ;;
        *) exit 0
esac
exit 0

but nothing happens when I disable and re-enable my network card but if I execute ./999startsynergy up manually, it works just fine! I've also tried with & without the 5 second delay - same thing... any idea what might be going on here?

  • Which distribution are you running? – zeppelin Nov 6 '16 at 22:03
  • @zeppelin Kubuntu 16.04 – stdcerr Nov 7 '16 at 1:52
2

synergyc requires an access to the X11 server (display), and should normally be run as a regular user too.

Scripts in /etc/network/if-up.d/ in turn, are run as root, and do not have access to your X11 display, which is why it does not work for you.

What you can do, is configure synergyc to connect to a proper X11 display (which will be :0, usually), by setting a DISPLAY environment variable, or supplying "--display" option to synergyc.

You can also use sudo to launch it as a proper user (that not strictly necessary, but is probably a good idea anyway).

Here is a small test script, for you to experiment with:

#!/bin/sh
[ "$IFACE" = "wlan0" ] || exit 0
export DISPLAY=:0
sudo -u YOUR_USER_NAME xclock &

Replace YOUR_USER_NAME with your regular account username, and wlan0 with your wi-fi interface name (in case it is different), and also make sure that you have xclock installed (it is normally a part of x11-apps package), then place this to your /etc/network/if-up.d/, and try switching the network interface on an off.

If everything goes well a xclock will pop-up each time your interface goes up, and you can then modify this to launch synergyc instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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