[SOLVED] How to Run iwconfig Commands After an Interface is Up?
SlackwareThis Forum is for the discussion of Slackware 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.
I don't want to have to do it manually every time I boot up or restart the network/interface.
hi, i think what you mean is to create a boot script right?
if thats the case then you just need to append the code you want to run in your /etc/rc.d/rc.local
or create a "rc.something" executable script in /etc/rc.d and then point to it in your /etc/rc.d/rc.local
also, althrough I don't think is the case, if you need to close/deactivate something upon shutdown, do the same in rc.local_shutdow
you can have a look at the scripts already present in rc.d/ to see how to create the script.
if you prefer to only write the commands as normal in terminal, just add them in order in rc.local, that script is always run at boot and parsed as normal commands
hi, i think what you mean is to create a boot script right?
if thats the case then you just need to append the code you want to run in your /etc/rc.d/rc.local
or create a "rc.something" executable script in /etc/rc.d and then point to it in your /etc/rc.d/rc.local
also, althrough I don't think is the case, if you need to close/deactivate something upon shutdown, do the same in rc.local_shutdow
you can have a look at the scripts already present in rc.d/ to see how to create the script.
if you prefer to only write the commands as normal in terminal, just add them in order in rc.local, that script is always run at boot and parsed as normal commands
bye
A boot script won't work. 1st of all, there is no assurance the interface will be up when rc.local runs and 2nd rc.local does not run after I restart the network or interface.
A boot script won't work. 1st of all, there is no assurance the interface will be up when rc.local runs
then i suppose i've really not understood what you want to do.
can you give us a little bit more info on what commands you want to use on boot?
also in order to be sure the interface is up when you pass the command i think ifconfig interface down && ifconfig interface up will ensure is up before the commands that came next.
rc.local is the last script parsed, so if you put those lines right before the iwconfig lines then the iwconfig commands will surely work.
Quote:
and 2nd rc.local does not run after I restart the network or interface.
then you could add the lines you need in a rc.something script with the "start stop restart" parameters, then if you truly need it add the parsing of that script inside rc.networkmanager or something like that.
However it will be much easier to help if you tell us exactly what you need to do.
rc.inetd rc.inet1 rc.inet2 rc.network manager and rc.wireless afaik already cover most of the use for network...
/etc/rc.d/rc.inet1 is a simple bash script so you can easily add to it the possibility to run dedicated scripts whenever a specific interface is brought up and down: in the following example I have modified it assuming your interface is wlan0
Code:
--- ./rc.inet1.orig 2016-09-20 20:21:19.000000000 +0200
+++ ./rc.inet1 2017-04-18 16:33:55.717052368 +0200
@@ -186,6 +186,7 @@
echo "/etc/rc.d/rc.inet1: ${1} is already up, skipping" | $LOGGER
fi
fi
+ [ "${1}" = "wlan0" -a -x /etc/rc.d/rc.wlan0_up ] && /etc/rc.d/rc.wlan0_up
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface does not exist (yet)" | $LOGGER
@@ -201,6 +202,7 @@
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
+ [ "${1}" = "wlan0" -a -x /etc/rc.d/rc.wlan0_down ] && /etc/rc.d/rc.wlan0_down
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then
if [ "${USE_DHCP[$i]}" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -k -d ${1}" | $LOGGER
then you have to write the two dedicated scripts, /etc/rc.d/rc.wlan0_up and /etc/rc.d/rc.wlan0_down, and make them executable.
If you're using Network Manager, you can add commands into scripts to be run after the network status changes. The location to add those scripts is /etc/networkmanager/dispatcher.d/. You can have as many scripts in there as you want. I imagine they're likely run in alphabetical order, but I've never checked.
The files can be matched to interfaces and whether the status has switched to up (connected) or down (disconnected).
Code:
#!/bin/bash
INTRFC=$1
STATUS=$2
if [ "$INTRFC" == "wlan0" ]
then
case "$2" in
up)
logger -s "Running something since network is up"
random
commands
here
;;
down)
logger -s "Running something since network is down"
random
commands
here
*)
;;
esac
fi
Keep in mind, the scripts are run as root, so take that into account when you have it doing things. Network Manager will run it with the interface and the status as arguments 1 and 2 respectively. If your device isn't wlan0, you'll want to change it to match (or you can remove checking for the interface by just removing the if/then/fi statement and only having the case/esac statement).
Also, scripts must be owned and executable by root and not be writeable by group or other, so I'd recommend running chmod 744 on it.
can you give us a little bit more info on what commands you want to use on boot?
In the early days some Linux wifi hardware drivers did not work very well or did not exist so you would use ndiswrapper (lets Linux use the Windows driver). I also researched what settings Windows used for various wireless parameters. Using those parameters on Linux improved the stability of the wifi device and gave fewer drop outs. Even with today's Linux drivers that is still true. I always run the following commands for all wifi devices.
/etc/rc.d/rc.inet1 is a simple bash script so you can easily add to it the possibility to run dedicated scripts whenever a specific interface is brought up and down: in the following example I have modified it assuming your interface is wlan0
Code:
--- ./rc.inet1.orig 2016-09-20 20:21:19.000000000 +0200
+++ ./rc.inet1 2017-04-18 16:33:55.717052368 +0200
@@ -186,6 +186,7 @@
echo "/etc/rc.d/rc.inet1: ${1} is already up, skipping" | $LOGGER
fi
fi
+ [ "${1}" = "wlan0" -a -x /etc/rc.d/rc.wlan0_up ] && /etc/rc.d/rc.wlan0_up
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface does not exist (yet)" | $LOGGER
@@ -201,6 +202,7 @@
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
+ [ "${1}" = "wlan0" -a -x /etc/rc.d/rc.wlan0_down ] && /etc/rc.d/rc.wlan0_down
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then
if [ "${USE_DHCP[$i]}" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -k -d ${1}" | $LOGGER
then you have to write the two dedicated scripts, /etc/rc.d/rc.wlan0_up and /etc/rc.d/rc.wlan0_down, and make them executable.
Thanks for the code, I think I can get it to work using that.
check /lib/udev/rules.d/75-persistent-net-generator.rules for ideas.
After your suggestion, I looked into this because it is more aesthetically pleasing than modifying a system script.
The purpose of udev is to populate/depopulate /dev when hardware is plugged in/unplugged.
I don't think I can do what I want with udev. udev has only 3 ACTIONs, add, remove and change. AFAICT, add means plug a device in, remove means unplug a device, and change means a change between plugging and unplugging. I could find no info on udev events that relates to internal state changes of a device.
Based on your post, I kinda expected this, but in case I was wrong, I wanted to throw the option out there. I've never used anything other than wpa_supplicant either (although, I don't have any wireless systems running Slackware right now).
In the early days some Linux wifi hardware drivers did not work very well or did not exist so you would use ndiswrapper (lets Linux use the Windows driver). I also researched what settings Windows used for various wireless parameters. Using those parameters on Linux improved the stability of the wifi device and gave fewer drop outs. Even with today's Linux drivers that is still true. I always run the following commands for all wifi devices.
Also power management causes problems for some wifi devices and since I don't use it, I turn it off.
Code:
iwconfig wlan0 power off
These commands do not work if the interface is not up. I have to run these commands every time the interface comes up.
as you haven't explained in the first place I thought your use case was different.
but if it's what you describe in this post this is already covered by /etc/rc.d/rc.wireless.conf: please open it with a root text editor, read it carefully and edit it accordingly (tell us if you need further help after).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.