The officially official Devuan Forum!

You are not logged in.

#1 2017-08-29 19:23:47

GNUser
Member
Registered: 2017-03-16
Posts: 561  

on network-manager, how to run bash script before connecting to wifi?

I have a bash script that I would like to run just before my system connects to any wireless network. Does anybody know how to accomplish this? I know wicd makes it easy with its "preconnect" directory, but I can't seem to figure out how to do it with network-manager, which is what I use now.

I know how to run scripts after connecting, but not before. The /etc/NetworkManager/dispatcher.d/pre-up.d directory sounds promising but is not exactly what I'm looking for because those jobs are actually run after the interface is connected:

pre-up

The interface is connected to the network but is not yet fully activated. Scripts acting on this event must be placed or symlinked into the /etc/NetworkManager/dispatcher.d/pre-up.d directory, and NetworkManager will wait for script execution to complete before indicating to applications that the interface is fully activated.

Any ideas?

Last edited by GNUser (2017-08-29 19:36:21)

Offline

#2 2017-08-29 21:27:27

garyz.dev1
Member
From: U.S.-South Carolina
Registered: 2017-06-15
Posts: 89  

Re: on network-manager, how to run bash script before connecting to wifi?

Well,  not in my experience area -- but is wicd run by a sysvinit script on startup??
You know - one of the rc.d type files iwth the numbers in the name for the start/kill priority.

Offline

#3 2017-08-30 00:45:04

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: on network-manager, how to run bash script before connecting to wifi?

Thanks, garyz, but I don't use wicd. I use network-manager.

I figured out a workaround. It doesn't actually run my script before every wifi connection, but does run the script before connecting to wifi at two critical times: after boot and after resuming from suspend. That's good enough for what I need.

Two scripts are required:

#!/bin/bash

# Save this one as /etc/init.d/jobs-preconnect

### BEGIN INIT INFO
# Provides:          jobs-preconnect
# Required-Start:    $remote_fs dbus udev
# Required-Stop:     $remote_fs dbus udev
# Should-Start:	     $syslog
# Should-Stop:       $syslog
# X-Start-Before:    network-manager
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: bruno's jobs-preconnect
# Description:       jobs to run before network-manager starts
### END INIT INFO

[ "$1" = "start" ] && /path/to/preconnect/script
#!/bin/bash

# Save this one as /etc/pm/sleep.d/33jobs-preconnect

if [[ "$1" = "resume" ]]; then
	service network-manager stop 
	bash /path/to/preconnect/script
	service network-manager start
fi

Then run these commands in a terminal as root:

chown root /etc/init.d/jobs-preconnect
chmod 755 /etc/init.d/jobs-preconnect
update-rc.d jobs-preconnect defaults
chown root /etc/pm/sleep.d/33jobs-preconnect
chmod 755 /etc/pm/sleep.d/33jobs-preconnect

Last edited by GNUser (2017-08-31 00:21:53)

Offline

Board footer