LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2014, 11:50 AM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
script to provide info necessary for network troubleshooting


i created this script called net-diag.ksh which i refer people to identify their network card and stuff:
Code:
#!/bin/bash

echo uname && uname -a -m -p &> /tmp/00-uname.schneidz && \
echo lspci && lspci &> /tmp/01-lspci.schneidz && \
echo lsusb && lsusb &> /tmp/02-lsusb.schneidz && \
echo lsmod && lsmod &> /tmp/03-lsmod.schneidz && \
echo ifconfig && ifconfig &> /tmp/04-ifconfig.schneidz && \
echo ifconfig -a && ifconfig -a &> /tmp/05-ifconfig-a.schneidz && \
echo iwconfig && iwconfig &> /tmp/06-iwconfig.schneidz && \
echo iwlist && sudo iwlist `awk '/IEEE/ {print $1}' /tmp/06-iwconfig.schneidz` scan &> /tmp/07-iwlist.schneidz && \
echo resolv.conf && cat /etc/resolv.conf &> 08-resolv.conf.schneidz && \
echo route && route -n &> /tmp/09-route.schneidz && \
echo ping router && ping -c 1 `route | awk '/default/ {print $2}'` &> /tmp/10-ping-router.schneidz && \
echo ping dns server && ping -c 1 `awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n 1` &> /tmp/11-ping-dns-server.schneidz && \
echo ping using ip && ping -c 1 64.235.229.141 &> /tmp/12-ping-using-ip.schneidz && \
echo ping using dns && ping -c 1 www.02144.com &> /tmp/13-ping-using-dns.schneidz

head -n 99999 /tmp/*.schneidz
one would basically need to copy-pasta the source code and save as net-diag.ksh.
then run it as source netdiag.ksh (or change perms like chmod 744 netdiag.ksh then run it like: ./net-diag.ksh).

whatever it spits out should be copy-pastad in the thread (in [code] tags) to give whoever wishes to answer a starting point for determining the issue.

critiques are welcome.

Last edited by schneidz; 06-27-2014 at 11:53 AM.
 
Old 07-01-2014, 01:13 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by schneidz View Post
critiques are welcome.
Thanks for the opportunity:
- not testing for binaries to use,
- predictable (fixed) file name instead of using `mktemp`,
- using multiple file names where one would suffice (also see use of 'head'),
- unnecessary use of double ampersands,
- no error checking (does `route | awk '/default/ {print $2}'` always present something one can resolve?).

*Ever heard of 'ss' or 'ip'? Esp. 'ip' can provide a lot of nfo in one tool. And what about protocol focus? UDP and ICMP are one thing but how about TCP? As in 'tcptraceroute'? Or content as in "curl -kI https://something"?
 
1 members found this post helpful.
Old 07-01-2014, 01:46 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
thanks,
double &&'s so that it stops at the step that it failed on.

head puts a header before each file so it is easier to scan thru a wall of text.

i've had good luck with parsing the route command but parsing /etc/resolv.conf for a nameserver sometimes gives an ipv6 address that ping chokes on.

ip seems very useful and will probably replace most of the steps.
 
Old 07-01-2014, 05:53 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
There's no need to do the double ampersands. You can start your script with...

Code:
set -e
See man bash. The set command is detailed at the end.

set -e will stop your script on first error and report the last error exit code. Regarding ip command like unspawn mentions I wrote a blog post which provides an example of obtaining the IP address for the interface of the default route. It uses the ip command.

SAM

Last edited by sag47; 07-01-2014 at 05:55 PM.
 
2 members found this post helpful.
Old 03-13-2015, 10:32 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
added rfkill
modified lspci:


i created this script called net-diag.ksh which i refer people to identify their network card and stuff:
Code:
#!/bin/bash

echo uname && uname -a -m -p &> /tmp/00-uname.schneidz && \
echo lspci && lspci -vvv -nn | awk 'BEGIN {RS="\n\n"} /Ethernet controller|Network controller/ {print $0}' &> /tmp/01-lspci.schneidz && \
echo lsusb && lsusb &> /tmp/02-lsusb.schneidz && \
echo lsmod && lsmod &> /tmp/03-lsmod.schneidz && \
echo ifconfig && ifconfig &> /tmp/04-ifconfig.schneidz && \
echo ifconfig -a && ifconfig -a &> /tmp/05-ifconfig-a.schneidz && \
echo iwconfig && iwconfig &> /tmp/06-iwconfig.schneidz && \
echo rfkill && rfkill list &> /tmp/07-rfkill.schneidz && \
echo iwlist && sudo iwlist `awk '/IEEE/ {print $1}' /tmp/06-iwconfig.schneidz` scan &> /tmp/08-iwlist.schneidz && \
echo resolv.conf && cat /etc/resolv.conf &> 09-resolv.conf.schneidz && \
echo route && route -n &> /tmp/10-route.schneidz && \
echo ping router && ping -c 1 `route | awk '/default/ {print $2}'` &> /tmp/11-ping-router.schneidz && \
echo ping dns server && ping -c 1 `awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n 1` &> /tmp/12-ping-dns-server.schneidz && \
echo ping using ip && ping -c 1 64.235.229.141 &> /tmp/13-ping-using-ip.schneidz && \
echo ping using dns && ping -c 1 www.02144.com &> /tmp/14-ping-using-dns.schneidz

head -n 99999 /tmp/*.schneidz
one would basically need to copy-pasta the source code and save as net-diag.ksh.
then run it as source netdiag.ksh (or change perms like chmod 744 netdiag.ksh then run it like: ./net-diag.ksh).

whatever it spits out should be copy-pastad in the thread (in [code] tags) to give whoever wishes to answer a starting point for determining the issue.

critiques are welcome.

Last edited by schneidz; 03-13-2015 at 11:49 AM.
 
Old 03-13-2015, 10:50 PM   #6
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
See posts #2 and #4. I would apply that same feedback to your most recent script. Additionally, just because you call a script *.ksh does not make it ksh. The shebang is what really matters unless you execute the script as an argument of the interpreter. In your case, the shebang is #!/bin/bash. So that's a bash script. If you want it to be ksh then you should update the shebang.
 
Old 03-13-2015, 11:42 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Nice but you're still:
- not testing for binaries you use,
- using predictable file names instead of using 'mktemp',
- using multiple file names...
 
  


Reply



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
provide password through script say_hi_ravi Programming 2 08-21-2010 06:26 AM
[SOLVED] Need dpkg to provide detailed info on virtualbox New2Linux2 Ubuntu 2 10-21-2009 10:38 AM
Interface which would provide complete System Information over the Network??? your_shadow03 Linux - Newbie 3 11-21-2008 09:35 AM
Does Ubuntu Linux Desktop provide network support? bmora96 Linux - Desktop 1 02-27-2008 05:58 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:49 PM.

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