Linux - Wireless NetworkingThis forum is for the discussion of wireless networking in Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it possible to use a shell script to turn wifi off and on in Linux?
Due to a company security policy, we can't use wifi networking except between midnight and 1AM. I have a laptop with wifi, that has to be disabled most of the time. It does have an Ethernet connection to a router that is not connected to the Internet.
The laptop needs to connect to the wireless network every day, do an update from the repositories and download some data. I want to create a cron job that runs at midnight and performs the following steps.
(1) Enable wifi and connect to the wireless network.
(2) Perform WGET operations to download a number of data files. Maybe do critical software updates.
(3) Turn the wifi back off.
(4) Reconnect to the local router via Ethernet.
So the script needs to be able to manage the network connections automatically, and it needs to be able to run repeatedly. We're not setting the connections up for the first time, just enabling/disabling them.
Is it possible to use a shell script to turn wifi off and on in Linux?
Due to a company security policy, we can't use wifi networking except between midnight and 1AM. I have a laptop with wifi, that has to be disabled most of the time. It does have an Ethernet connection to a router that is not connected to the Internet.
The laptop needs to connect to the wireless network every day, do an update from the repositories and download some data. I want to create a cron job that runs at midnight and performs the following steps.
(1) Enable wifi and connect to the wireless network.
(2) Perform WGET operations to download a number of data files. Maybe do critical software updates.
(3) Turn the wifi back off.
(4) Reconnect to the local router via Ethernet.
So the script needs to be able to manage the network connections automatically, and it needs to be able to run repeatedly. We're not setting the connections up for the first time, just enabling/disabling them.
Very possible...and also very pointless in the scenario you're describing. Since you say the laptop is ON, and already connected to the local wired network, then why turn on wifi at all??? Download what you need over the wired connection.
You can use ifconfig to bring an interface up/down, and wget to do whatever else you need for downloading. Should be very easy to script...there are thousands of bash scripting tutorials you can find with a brief Google search. Where are you stuck?? What have you written so far? We're happy to help, but we WILL NOT write your script for you.
It does have an Ethernet connection to a router that is not connected to the Internet.
Whoops...missed that part.
Still confusing, though...hard to imagine a network that does NOT have an outbound connection somehow, or that wifi is only available for one hour a day, in the middle of the night, or there aren't some sort of provisions made at the company to let folks do updates during the day.
They have a disconnected subnet. There is a policy that the systems on the local network can't get data from the Internet except for a single data file that we need to download on a daily basis. There's also a policy that we can't have radio signals. The only exception is for an hour at night when it's OK to turn on the radio. But even then, the subnet stays disconnected and only this one laptop can perform this one update.
So they have a wired router that is not connected to the Internet. I have an Ethernet cable from the laptop to that local router. I need to pull down a data file and the easiest thing seems to be, do it over wifi during the night when the wireless signal is available for one hour. While I'm at it, I can get updates.
Here's a script I have worked out since I posted this question yesterday. It's intended to be run as root from a cron job.
Code:
# turn off the ethernet interface.
ifconfig eth0 disable
# turn on wifi interface.
ifconfig wlan0 enable
# turn on wifi radio
iwconfig wlan0 txpower on
# repository update (optional)
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
# Download update data file
wget url-of-data-file
chown user name-of-file
# turn off radio power
iwconfig wlan0 txpower off
# turn off wifi interface
ifconfig wlan0 disable
# turn ethernet back on
ifconfig eth0 enable
I would be grateful if anyone has criticisms or maybe there's some flaw in the script, or issue I'm not aware of. I'm separately turning off and on the radio just to be sure there's no interference.
They have a disconnected subnet. There is a policy that the systems on the local network can't get data from the Internet except for a single data file that we need to download on a daily basis. There's also a policy that we can't have radio signals. The only exception is for an hour at night when it's OK to turn on the radio. But even then, the subnet stays disconnected and only this one laptop can perform this one update.
So they have a wired router that is not connected to the Internet. I have an Ethernet cable from the laptop to that local router. I need to pull down a data file and the easiest thing seems to be, do it over wifi during the night when the wireless signal is available for one hour. While I'm at it, I can get updates.
Here's a script I have worked out since I posted this question yesterday. It's intended to be run as root from a cron job.
Code:
# turn off the ethernet interface.
ifconfig eth0 disable
# turn on wifi interface.
ifconfig wlan0 enable
# turn on wifi radio
iwconfig wlan0 txpower on
# repository update (optional)
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
# Download update data file
wget url-of-data-file
chown user name-of-file
# turn off radio power
iwconfig wlan0 txpower off
# turn off wifi interface
ifconfig wlan0 disable
# turn ethernet back on
ifconfig eth0 enable
I would be grateful if anyone has criticisms or maybe there's some flaw in the script, or issue I'm not aware of. I'm separately turning off and on the radio just to be sure there's no interference.
That looks like it'll work nicely, providing you don't encounter any errors. If any of those steps fail, the rest will just continue on, or try to...but if it's not critical, it shouldn't matter, especially if you're just doing apt-get's and downloading a single file.
Since this is for a company, I'd suggest you get with your data-security folks, and ask them to work with you, to provide a more bulletproof solution that fits in with your company's policies. Perhaps putting a dedicated VM Server in your DMZ, that does NOTHING but fetch such things, and acts as a repository would be in order. That would leave that machine in their control, and you could update as you see fit during the day.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.