Run script after successful wireless connection

imo92

New Member
Joined
Oct 31, 2019
Messages
2
Reaction score
0
Credits
0
I need a way to run a script when a successful wireless connection is made.

I'm using Lubuntu 16.04 (although I've attempted this on Lubuntu and Ubuntu 18.04 with no success.)

My script is pretty simple:
Code:
#!/bin/bash

xtightvncviewer 192.168.0.10

Whenever computer A starts up and successfully connects to the wireless network, I require the script to run, which VNC's to computer B.

I've added this script to /etc/network/if-up.d with sudo cp, thereafter I made it executable with sudo chmod +x, and made root the owner with sudo chown root.

This script runs fine if I execute it from the terminal or manually execute it.

When I connect the PC to the network, my syslog states:

nm-dispatcher: req:1 'up' [enp3s0]: new request (1 scripts)
nm-dispatcher: req:1 'up' [enp3s0]: start running ordered scripts...
nm-dispatcher[3298]: Error: Can't open display:
nm-dispatcher[3298]: run-parts: /etc/network/if-up.d/vnc exited with return code 1

I'm unsure where I'm going wrong or perhaps if I'm doing this completely the wrong way, since being new to Linux.

I'm open to using other applications or distros if it would help me at this point.
Any assistance or ideas welcome.
 


The "Error can't open display" message usually gets thrown if X (or wayland) hasn't started yet. Graphical applications cannot run until AFTER X (or wayland) have started. And if memory serves VNC is a graphical application.

So perhaps you should set your script up to run after you've logged-in, rather than as soon as the network connection is up?
The network connection is almost always up before the login-manager/window manager/desktop is loaded. So that is almost certainly the cause of the problem.

Again - the reason the script works from a terminal, or manually is because at that point in time - X (or wayland) is already running your chosen WM/desktop - so vnc will be able to access the display!
 
@JasKinasis I believe you correct that VNC is a graphical application, as it does provide a remote view into another PC. However I don't think the issue is the network connection going up before the desktop is loaded because I tested this.

If I boot up my PC without a network connection, wait for some time to ensure the desktop is full loaded, and then connect my network cable and join the network, I get the same syslog, and the timestamp is of when I connect the network cable.

nm-dispatcher: req:1 'up' [enp3s0]: new request (1 scripts)
nm-dispatcher: req:1 'up' [enp3s0]: start running ordered scripts...
nm-dispatcher[3298]: Error: Can't open display:
nm-dispatcher[3298]: run-parts: /etc/network/if-up.d/vnc exited with return code 1

Is there a way to Open the display/ assign a display via my script perhaps?
 

Members online


Top