How to only start network interface when usb-stick is connected?Bridging ethernet interfaceeth0 not getting...
After a few interviews, What should I do after told to wait?
Sinning and G-d's will, what's wrong with this logic?
Did "Dirty Harry" feel lucky?
Relationship between speed and cadence?
What is the extent of the commands a Cambion can issue through Fiendish Charm?
Laptop failure due to constant fluctuation of AC frequency and voltage
Where on Earth is it easiest to survive in the wilderness?
How to interpret or parse this confusing 'NOT' and 'AND' legal clause
How to best explain that you are taking pictures in a space for practice reasons?
Let A,B,C be sets. If A△B=A△C, does this imply that B=C?
Python reimplementation of Lost In Space by Tim Hartnell
How do you say "to hell with everything" in French?
Filling attribute tables with values from the same attribute table
Is mountain bike good for long distances?
When does order matter in probability?
What's this inadvertent thing?
What can we do about our 9-month-old putting fingers down his throat?
What makes an ending "happy"?
Why can't some airports handle heavy aircraft while others do it easily (same runway length)?
Supervisor wants me to support a diploma-thesis SW tool after I graduated
What exactly is Apple Cider
At what point does a land become controlled?
What is the purpose of the rotating plate in front of the lock?
I won a car in a poker game. How is that taxed in Canada?
How to only start network interface when usb-stick is connected?
Bridging ethernet interfaceeth0 not getting disabled after setting up br0 interfaceUsing ip addr instead of ifconfig reports “RTNETLINK answers: File exists” on DebianWait for a network device to come up before bringing another network device up on boot?How to assign two iface to different subnets?Can't enable net.ipv6.conf.eth0.autoconfUbuntu 15.10 Network Interfaces NameHow do I set additional IP addresses on an existing interface in Debian 9?How to connect 2 virtual bridges so traffic goes from one to the other?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a tinkerboard setup, that it start its network configuration on startup, and opens a bridge. Now I need a setup, where the wlan only boots, when i connect an external device. Preferably if a usb stick is connected it should come up, otherwise the wlan should stay disabled. (and the bridge as well). The check should only happen on startup, i do not need a later check.
I thought about adding a line in the pre-up statement of the wlan interface if an usb device is connected, while checking if the directory where it supposed to be exists. But this does not yield any results. See the marked line in the code below.
Any ideas how to solve that issue?
Thanks in advance.
Lennart
➜ ~ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#### FOR Access Point ####
# localhost
auto lo
iface lo inet loopback
# wireless interface
allow-hotplug wlan0
#pre-up [-d "/sys/block/sda"] <-- Here i wanted to check if the usb is connected
iface wlan0 inet manual
iface wlan0 inet6 manual
# ethernet interface
allow-hotplug eth0
iface eth0 inet manual
iface eth0 inet6 manual
# network bridge with static ip adress
auto br0
iface br0 inet static
pre-up ifup wlan0 eth0
bridge_ports eth0 wlan0
bridge_fd 0
bridge_stp off
address 192.168.1.100
broadcast 192.168.1.255
netmask 255.255.255.0
networking wifi ifconfig
migrated from serverfault.com 21 mins ago
This question came from our site for system and network administrators.
add a comment |
I have a tinkerboard setup, that it start its network configuration on startup, and opens a bridge. Now I need a setup, where the wlan only boots, when i connect an external device. Preferably if a usb stick is connected it should come up, otherwise the wlan should stay disabled. (and the bridge as well). The check should only happen on startup, i do not need a later check.
I thought about adding a line in the pre-up statement of the wlan interface if an usb device is connected, while checking if the directory where it supposed to be exists. But this does not yield any results. See the marked line in the code below.
Any ideas how to solve that issue?
Thanks in advance.
Lennart
➜ ~ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#### FOR Access Point ####
# localhost
auto lo
iface lo inet loopback
# wireless interface
allow-hotplug wlan0
#pre-up [-d "/sys/block/sda"] <-- Here i wanted to check if the usb is connected
iface wlan0 inet manual
iface wlan0 inet6 manual
# ethernet interface
allow-hotplug eth0
iface eth0 inet manual
iface eth0 inet6 manual
# network bridge with static ip adress
auto br0
iface br0 inet static
pre-up ifup wlan0 eth0
bridge_ports eth0 wlan0
bridge_fd 0
bridge_stp off
address 192.168.1.100
broadcast 192.168.1.255
netmask 255.255.255.0
networking wifi ifconfig
migrated from serverfault.com 21 mins ago
This question came from our site for system and network administrators.
add a comment |
I have a tinkerboard setup, that it start its network configuration on startup, and opens a bridge. Now I need a setup, where the wlan only boots, when i connect an external device. Preferably if a usb stick is connected it should come up, otherwise the wlan should stay disabled. (and the bridge as well). The check should only happen on startup, i do not need a later check.
I thought about adding a line in the pre-up statement of the wlan interface if an usb device is connected, while checking if the directory where it supposed to be exists. But this does not yield any results. See the marked line in the code below.
Any ideas how to solve that issue?
Thanks in advance.
Lennart
➜ ~ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#### FOR Access Point ####
# localhost
auto lo
iface lo inet loopback
# wireless interface
allow-hotplug wlan0
#pre-up [-d "/sys/block/sda"] <-- Here i wanted to check if the usb is connected
iface wlan0 inet manual
iface wlan0 inet6 manual
# ethernet interface
allow-hotplug eth0
iface eth0 inet manual
iface eth0 inet6 manual
# network bridge with static ip adress
auto br0
iface br0 inet static
pre-up ifup wlan0 eth0
bridge_ports eth0 wlan0
bridge_fd 0
bridge_stp off
address 192.168.1.100
broadcast 192.168.1.255
netmask 255.255.255.0
networking wifi ifconfig
I have a tinkerboard setup, that it start its network configuration on startup, and opens a bridge. Now I need a setup, where the wlan only boots, when i connect an external device. Preferably if a usb stick is connected it should come up, otherwise the wlan should stay disabled. (and the bridge as well). The check should only happen on startup, i do not need a later check.
I thought about adding a line in the pre-up statement of the wlan interface if an usb device is connected, while checking if the directory where it supposed to be exists. But this does not yield any results. See the marked line in the code below.
Any ideas how to solve that issue?
Thanks in advance.
Lennart
➜ ~ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#### FOR Access Point ####
# localhost
auto lo
iface lo inet loopback
# wireless interface
allow-hotplug wlan0
#pre-up [-d "/sys/block/sda"] <-- Here i wanted to check if the usb is connected
iface wlan0 inet manual
iface wlan0 inet6 manual
# ethernet interface
allow-hotplug eth0
iface eth0 inet manual
iface eth0 inet6 manual
# network bridge with static ip adress
auto br0
iface br0 inet static
pre-up ifup wlan0 eth0
bridge_ports eth0 wlan0
bridge_fd 0
bridge_stp off
address 192.168.1.100
broadcast 192.168.1.255
netmask 255.255.255.0
networking wifi ifconfig
networking wifi ifconfig
asked 11 hours ago
LennyLenny
11 bronze badge
11 bronze badge
migrated from serverfault.com 21 mins ago
This question came from our site for system and network administrators.
migrated from serverfault.com 21 mins ago
This question came from our site for system and network administrators.
migrated from serverfault.com 21 mins ago
This question came from our site for system and network administrators.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The easiest way I can think of right now would be to create a partition with a readable file system on your usb and update your /etc/fstab using the UUID of that partition to always mount it to a specific location:
# /etc/fstab
...
UUID=12345678-1234-5678-1234-123456789012 /mnt/trigger_usb ext4 noatime 0 1
...
Then create a file on that partition touch /mnt/trigger_usb/trigger.
Now the hard part is dependent upon whether you use systemd or some sort of RC (OpenRC).
For example, on systemd you would have to create a unit file under (might be system dependent) /etc/systemd/system/conditional_wifi.service
[Unit]
Description=Wifi Conditional Startup
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/path/to/your/start/script.sh
ExecReload=/path/to/your/reload/script.sh
ExecStop=/path/to/your/stop/script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
and enable it systemctl enable conditional_wifi.service.
Create a script.sh which would check the existence of the file
#!/bin/bash
if [ -e /mnt/trigger_usb/trigger ]; then
# start your wifi here
fi
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like sols -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employlsusband go from there.
– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539441%2fhow-to-only-start-network-interface-when-usb-stick-is-connected%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The easiest way I can think of right now would be to create a partition with a readable file system on your usb and update your /etc/fstab using the UUID of that partition to always mount it to a specific location:
# /etc/fstab
...
UUID=12345678-1234-5678-1234-123456789012 /mnt/trigger_usb ext4 noatime 0 1
...
Then create a file on that partition touch /mnt/trigger_usb/trigger.
Now the hard part is dependent upon whether you use systemd or some sort of RC (OpenRC).
For example, on systemd you would have to create a unit file under (might be system dependent) /etc/systemd/system/conditional_wifi.service
[Unit]
Description=Wifi Conditional Startup
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/path/to/your/start/script.sh
ExecReload=/path/to/your/reload/script.sh
ExecStop=/path/to/your/stop/script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
and enable it systemctl enable conditional_wifi.service.
Create a script.sh which would check the existence of the file
#!/bin/bash
if [ -e /mnt/trigger_usb/trigger ]; then
# start your wifi here
fi
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like sols -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employlsusband go from there.
– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
add a comment |
The easiest way I can think of right now would be to create a partition with a readable file system on your usb and update your /etc/fstab using the UUID of that partition to always mount it to a specific location:
# /etc/fstab
...
UUID=12345678-1234-5678-1234-123456789012 /mnt/trigger_usb ext4 noatime 0 1
...
Then create a file on that partition touch /mnt/trigger_usb/trigger.
Now the hard part is dependent upon whether you use systemd or some sort of RC (OpenRC).
For example, on systemd you would have to create a unit file under (might be system dependent) /etc/systemd/system/conditional_wifi.service
[Unit]
Description=Wifi Conditional Startup
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/path/to/your/start/script.sh
ExecReload=/path/to/your/reload/script.sh
ExecStop=/path/to/your/stop/script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
and enable it systemctl enable conditional_wifi.service.
Create a script.sh which would check the existence of the file
#!/bin/bash
if [ -e /mnt/trigger_usb/trigger ]; then
# start your wifi here
fi
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like sols -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employlsusband go from there.
– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
add a comment |
The easiest way I can think of right now would be to create a partition with a readable file system on your usb and update your /etc/fstab using the UUID of that partition to always mount it to a specific location:
# /etc/fstab
...
UUID=12345678-1234-5678-1234-123456789012 /mnt/trigger_usb ext4 noatime 0 1
...
Then create a file on that partition touch /mnt/trigger_usb/trigger.
Now the hard part is dependent upon whether you use systemd or some sort of RC (OpenRC).
For example, on systemd you would have to create a unit file under (might be system dependent) /etc/systemd/system/conditional_wifi.service
[Unit]
Description=Wifi Conditional Startup
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/path/to/your/start/script.sh
ExecReload=/path/to/your/reload/script.sh
ExecStop=/path/to/your/stop/script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
and enable it systemctl enable conditional_wifi.service.
Create a script.sh which would check the existence of the file
#!/bin/bash
if [ -e /mnt/trigger_usb/trigger ]; then
# start your wifi here
fi
The easiest way I can think of right now would be to create a partition with a readable file system on your usb and update your /etc/fstab using the UUID of that partition to always mount it to a specific location:
# /etc/fstab
...
UUID=12345678-1234-5678-1234-123456789012 /mnt/trigger_usb ext4 noatime 0 1
...
Then create a file on that partition touch /mnt/trigger_usb/trigger.
Now the hard part is dependent upon whether you use systemd or some sort of RC (OpenRC).
For example, on systemd you would have to create a unit file under (might be system dependent) /etc/systemd/system/conditional_wifi.service
[Unit]
Description=Wifi Conditional Startup
DefaultDependencies=no
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/path/to/your/start/script.sh
ExecReload=/path/to/your/reload/script.sh
ExecStop=/path/to/your/stop/script.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
and enable it systemctl enable conditional_wifi.service.
Create a script.sh which would check the existence of the file
#!/bin/bash
if [ -e /mnt/trigger_usb/trigger ]; then
# start your wifi here
fi
answered 10 hours ago
Tom TrebickyTom Trebicky
1263 bronze badges
1263 bronze badges
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like sols -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employlsusband go from there.
– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
add a comment |
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like sols -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employlsusband go from there.
– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Thank you, that does sound though as if i would need a specific usb stick with that UUID then. I would prefer it to be any usb stick, sicne in the end i want to have the image on different boards and they all should be triggerable. Do you have any ideas how to achive that?
– Lenny
10 hours ago
Sure, check on the sole existence of a connected usb like so
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employ lsusb and go from there.– Tom Trebicky
10 hours ago
Sure, check on the sole existence of a connected usb like so
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk '{print $NF}'| awk -F "/" '{print $NF}' | sort. Or you could employ lsusb and go from there.– Tom Trebicky
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
so basically swap the if part of the script.sh to check for a usb. Alright i will try that. Thank you, will let you know if i was successful
– Lenny
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
Yes, give it a try and if you need further help, let me know.
– Tom Trebicky
10 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539441%2fhow-to-only-start-network-interface-when-usb-stick-is-connected%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown