LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 03-14-2022, 12:06 AM   #1
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Rep: Reputation: Disabled
Bash Networking Script


All,

Both iwconfig and ifconfig will give you the name of both your wired and wifi connections, if available. Wondering if there is, in some BASH libraries, a script that extracts the wired name if passed "lan" as an input var, or wifi name if passed "wifi" as the input var.

I currently have 2 scripts named 1.) lan-start.sh, 2.) wifi-start.sh. I wrote both of these over 5 years back when 'eth0' was always the wired connection and wlan0 was always the wifi connection. Can't use those anymore.

Want to simplify with one 'netw-start.sh' script that I can pass the "lan" or "wifi" options and it will:
  1. Extract the appropriate connection name,
  2. Restart the connection,
  3. Start DHCP
  4. Ping Goog 3 times to confirm successful connect.

An additional option would be to lookup the router UID/PWD in a file and get the router status, reporting if the router is down or in need of restart.

Cheers!

TBNK

Last edited by TBotNik; 03-14-2022 at 12:08 AM.
 
Old 03-14-2022, 10:17 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,297

Rep: Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327Reputation: 1327
I think current naming convention is that all ethernet will start with 'e' and wi-fi with 'w' regardless of remaining letters, so this works for me:

Code:
ether=$(ip link | awk '/^[0-9]+: e/ {sub(":","",$2); print $2}' |head -n1)
wifi=$(ip link | awk '/^[0-9]+: w/ {sub(":","",$2); print $2}' |head -n1)
There would be a problem with multiple interfaces of the same type when you don't want the first one.
 
Old 03-14-2022, 10:30 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,644

Rep: Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280Reputation: 6280
Ubuntu uses Network Manager which configured will automatically switch between ethernet and wireless adapters as well as start the dhcp client. You can use nmcli to manually switch or start, stop a connection.

You can go back to using network scripts to manage networking but you need to edit the files etc so that more or less will define the names used in your other script.

Last edited by michaelk; 03-14-2022 at 05:56 PM.
 
  


Reply

Tags
bash, lan, script, wifi


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
[SOLVED] Running bash script from another bash script bulletproof.rs Programming 5 12-10-2017 04:22 AM
[SOLVED] BASH Script - What am I doing wrong in this test? - BASH Script BW-userx Programming 34 04-08-2017 01:36 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM
Permissions on script sudo ln -s ../init.d/start-networking S90start-networking cnolasco Ubuntu 3 04-03-2007 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:10 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