LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-18-2017, 06:36 AM   #1
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Rep: Reputation: 33
How to Run iwconfig Commands After an Interface is Up?


I want to run some iwconfig commands after my wifi interface is up.

Gentoo lets you put a postup() function in its network configuration file to do that.

How would I do the same thing with Slackware?
 
Old 04-18-2017, 07:35 AM   #2
kudsu
Member
 
Registered: Apr 2017
Location: from LA
Distribution: Slackware and anything
Posts: 50

Rep: Reputation: Disabled
Why wouldn't you open a separate terminal and run commands there.
 
Old 04-18-2017, 07:42 AM   #3
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by kudsu View Post
Why wouldn't you open a separate terminal and run commands there.
I don't want to have to do it manually every time I boot up or restart the network/interface.
 
Old 04-18-2017, 07:53 AM   #4
Spike8605
LQ Newbie
 
Registered: Apr 2017
Posts: 20

Rep: Reputation: Disabled
Quote:
Originally Posted by bilbod View Post
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

bye

Last edited by Spike8605; 04-18-2017 at 07:55 AM.
 
Old 04-18-2017, 08:03 AM   #5
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by Spike8605 View Post
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.
 
Old 04-18-2017, 09:34 AM   #6
Spike8605
LQ Newbie
 
Registered: Apr 2017
Posts: 20

Rep: Reputation: Disabled
Quote:
Originally Posted by bilbod View Post
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...
 
Old 04-18-2017, 09:41 AM   #7
ponce
LQ Guru
 
Registered: Aug 2004
Location: Pisa, Italy
Distribution: Slackware
Posts: 7,090

Rep: Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173
/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.
 
2 members found this post helpful.
Old 04-18-2017, 10:25 AM   #8
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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.
 
Old 04-18-2017, 11:10 AM   #9
clavisound
LQ Newbie
 
Registered: Apr 2011
Posts: 15

Rep: Reputation: 1
I suppose you can also do this with udev but it's harder than bassmadrigal suggestion.

Example for iPad insertion.
Code:
ACTION=="add", SUBSYSTEMS=="usb", ATTR{idVendor}=="05ac", ATTR{idProduct}=="129f", RUN+="/lib/udev/ipad.script"
check /lib/udev/rules.d/75-persistent-net-generator.rules for ideas.
 
Old 04-18-2017, 06:47 PM   #10
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by Spike8605 View Post
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.

Code:
iwconfig wlan0 retry 30
iwconfig wlan0 frag 2346
iwconfig wlan0 rts 2347
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.
 
1 members found this post helpful.
Old 04-18-2017, 06:48 PM   #11
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by ponce View Post
/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.
 
Old 04-18-2017, 07:05 PM   #12
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by bassmadrigal View Post
If you're using Network Manager, you can add commands into scripts to be run after the network status changes.
I don'y use network manager, just wpa_supplicant.
 
Old 04-18-2017, 07:18 PM   #13
bilbod
Member
 
Registered: Mar 2003
Posts: 134

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by clavisound View Post
I suppose you can also do this with udev but it's harder than bassmadrigal suggestion.

Example for iPad insertion.
Code:
ACTION=="add", SUBSYSTEMS=="usb", ATTR{idVendor}=="05ac", ATTR{idProduct}=="129f", RUN+="/lib/udev/ipad.script"
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.
 
Old 04-18-2017, 07:28 PM   #14
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by bilbod View Post
I don'y use network manager, just wpa_supplicant.
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).
 
Old 04-18-2017, 11:41 PM   #15
ponce
LQ Guru
 
Registered: Aug 2004
Location: Pisa, Italy
Distribution: Slackware
Posts: 7,090

Rep: Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173Reputation: 4173
Quote:
Originally Posted by bilbod View Post
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.

Code:
iwconfig wlan0 retry 30
iwconfig wlan0 frag 2346
iwconfig wlan0 rts 2347
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).

Last edited by ponce; 04-19-2017 at 12:00 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iwconfig and Interface behavior onyxdragun Linux - Wireless Networking 1 01-05-2015 11:35 AM
Set-up a network interface with commands?? helptonewbie Linux - Newbie 2 11-22-2007 04:45 AM
iwconfig problems Commands won't work. goldsaturn25 Linux - Wireless Networking 14 10-03-2005 07:29 AM
commands for graphical interface lyler Linux - Newbie 1 08-06-2004 08:47 AM
modprobe, iwconfig, lsusb and other missing commands dubya Linux - Newbie 3 05-04-2004 09:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration