On Wed, 28 Jun 2017 10:35:00 -0000 (UTC), Dan Purgert wrote:
> Bit Twister wrote:
>> [...]
>> He might also want to consider starting a file containing anything he
>> has to look up more than a few times and a script to search it for
>> keywords.
>>
>> [...]
>>
>> uh is a link to my ux script, which know which item to search with
>> whatever words are provided.
>
> I really have to find that post I saved with your 'ux' / 'uh' script...
Well, it do make search man page topics much easier. :)
Should not be to find,
grep -i 'ux - search different files with user supplied keywords' /wherever/*
>
>> [...]
>> For example a network check script is more preferable than me having to
>> to run tests manually to find a failure point. Example:
>>
>> ---------------------
>> $ network_ck
>> [...]
>
> You wouldn't happen to have these tools on github or somewhere would
> you?
No, All my stuff is highly customized for my environment, coding
methodology and current Linux distribution.
My network_ck script is designed to run differently on different setups and
different ISP and tell me which cable is at fault and currently has
$ sort -u network_ck | grep -v '#' | wc -l
416
lines of code and verbage.
Like my posted ux script, here is a chopped down simplified beginners
copy you can play with.
-----8<-----8<-----8<--cut below this line----8<-----8<-----8<
#!/bin/bash
#************************************************************************
#*
#* network_ck - check each network item Release: 1.0
#*
#* Your router has a WAN ip address that you can ping.
#* You can get your internet/wan ip address with one the following:
#* wget -O-
http://icanhazip.com 2>/dev/null
#* curl
http://icanhazip.com/
#* curl
http://myip.dnsomatic.com
#* Be sure to change 0.0.0.6 in "_wan_ip" to your WAN ip address
#*
#* You can look in your router and change _dns_isp="8.8.8.8 208.67.222.222"
#* to the router value sent by your ISP for testing.
#* Note: It can change over time.
#*
#*
#* Install:
#* save script to network_ck
#* chmod +x network_ck
#* test with command ./network_ck
#* When done:
#* cp network_ck /usr/local/bin
#*
#*
#* set _debug="debug" to see all failure messages
#*
#* Assumptions: dig is installed and script is running in Linux/Unix OS
#* If using ipv6 addresses, ping6 is installed.
#*
#*
#*
#* This is free software released to public domain. Do with it whatever you want.
#*
#*
#************************************************************************
export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
set -u # Show usage of unset variables as an error, to help catch typos.
_app=$(basename $0) # application name
_count=0 # temporary count variable
_ck_nic_ary=() # array of nic ip to test
_debug="" # =debug will cause all test to fail
_dns="" # temp dns ip storage
_dns_rtr="" # router dns server ip
_dns_isp="8.8.8.8 208.67.222.222" # ISP dns server
_exe=$0 # full path spec of this script
_fix_msg="" # temp fix message storage
_fix_msg_ary=() # array of fix/check instructions
_failures=0 # running failure counter
_gw_lan_ip="" # lan gateway ip address
_gw_isp_ip="" # ISP gateway ip address
_host_alias="\"$(hostname --short)\""
_host_fqdn="$(hostname --fqdn)"
_host_ip="\"$(hostname --ip-address)\""
_ip="" # temp ip variable for ping test
_ix=0 # temp index var for ck_nic and fix_msg access
_ping_cmd="" # temp ping command variable
_test_msg="" # temp test message variable
_test=0 # current test indicator
_tmp="" # temporary string variable
_tmp_fn=/var/tmp/$_app.tmp # temporary file name used for ping output
_wan_ip="0.0.0.6" # ISP gateway your router is chatting with
_yahoo_ip="98.139.183.24" # current
yahoo.com ip address
set -- $(ip route)
_gw_lan_ip=$3 # set LAN gateway ip
set -- $(grep --max-count=1 nameserver /etc/resolv.conf)
_dns_rtr=$2
if [ -n "$_debug" ] ; then # set some known failure test cases
_host_alias="\"wbx tbx\""
_host_ip="\"192.168.111.135 192.168.111.100\""
fi
set -- $(IFS='.' ; echo $_wan_ip)
_gw_isp_ip=$1.$2.$3.1
##############################################################
# You can hard code value(s) here if you like
# if $(hostname whatever) is not providing normal results
# Example:
# _host_alias="just"
# _host_fqdn="just.me.here"
# _host_ip="192.168.3.3"
#
##############################################################
##############################################################
#
# This section loads what ip address is to be tested and the
# repair/troubleshooting text arrays
#
# _ck_nic_ary format is
# ip_address_to test and a brief what is being tested string
#
# _fix_msg_ary is whatever verbiage you want displayed when
# the test fails.
#
# Example test for printer:
#
# _ck_nic_ary+=("x.x.x.x printer is alive")
# _fix_msg_ary+=("Check power cord, is on, and nic led at printer")
#
##############################################################
_ck_nic_ary+=("127.0.0.1 ping and network is working on $_host_fqdn")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts")
_ck_nic_ary+=("localhost resolver reads /etc/hosts ")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts
Or /etc/nsswitch.conf hosts: entry needs adjustment
man nsswitch.conf
My settings: grep hosts /etc/nsswitch.conf
# hosts: mdns4_minimal files nis dns mdns4 myhostname
hosts: files dns myhostname")
#**************************************************
#* check if node's ip address has more than one value
#* If so, add a test for each one found.
#***************************************************
set -- $_host_ip
if [ $# -ne 1 ] ; then
_tmp="\\n\\tExpected only one ip address, not $_host_ip"
else
_tmp=""
fi
for _ip in $_host_ip ; do
_ck_nic_ary+=("$_ip $_host_alias nic access by ip address. $_tmp")
_fix_msg_ary+=("check led on nic socket.
use ethtool to see if it can read the hardware registers")
done
_tmp=""
_ck_nic_ary+=("$_host_fqdn resolver resolves by FQDN ")
_fix_msg_ary+=("")
#**********************************************
#* check if node's alias has more than one value
#* If so, add a test for each one found.
#**********************************************
set -- $_host_alias
if [ $# -ne 1 ] ; then
_tmp="\\n\\tExpected only one alias, not $_host_alias"
else
_tmp=""
fi
for _ip in $_host_ip ; do
_ck_nic_ary+=("$_host_alias resolver resolves by alias. $_tmp ")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts
If it is on the localhost line you need to create a separate line for each
Example:
127.0.0.1 localhost.localdomain localhost
127.0.0.2 darkstar.home.test darkstar
127.0.0.3 mail.home.test mail")
done
_tmp=""
_ck_nic_ary+=("$_gw_lan_ip $_host_alias to router gateway")
_fix_msg_ary+=("Check nic led on router. reset router and $_host_alias")
_ck_nic_ary+=("$_wan_ip ISP assigned Internet ip adress")
_fix_msg_ary+=("Verify your WAN Internet ip address has not changed.
You can get your Internet/WAN ip address with one the following:
wget -O-
http://icanhazip.com 2>/dev/null
curl
http://icanhazip.com/
curl
http://myip.dnsomatic.com
Some ISPs block pings so you need to verify you can ping the address.
If ping fails, it is blocked and you need to set _wan_ip=127.0.0.1
If works, change $_wan_ip to new value and rerun test. If still broke,
check nic leds on wire to wallplug
or coax led on the front of cable modem and reboot router.
Still broke, check all coax connections.
Still broke, it is an ISP router, coax, ONT, or ISP problem
call ISP to let them troubleshoot back to your modem")
_ck_nic_ary+=("$_gw_isp_ip ISP gateway ip adress")
_fix_msg_ary+=("Reboot ISP router. Still broke, call helpdesk")
_ck_nic_ary+=("$_dns_rtr router DNS node is alive ")
_fix_msg_ary+=("Reboot router. Still broke, call helpdesk")
_ck_nic_ary+=("$_yahoo_ip ISP can route to
yahoo.com ip address ")
_fix_msg_ary+=("
yahoo.com ip address may have changed or is down
ping -c1 -w1 8.8.8.8 If that works you have ISP Internet connectivity
ping -c1 -w1
yahoo.com if address is not $_yahoo_ip
change both in $_exe")
_ck_nic_ary+=("
yahoo.com ISP can get a DNS result to
yahoo.com")
_fix_msg_ary+=("Something wrong on the Internet
or one of the DNS servers in your connection/path is AFU")
function ping_nic ()
{
#**************************
#* test ip address via ping
#**************************
$_ping_cmd > $_tmp_fn 2>&1
if [ $? -ne 0 ] ; then
echo -e "$_test FAILURE Testing $_ip $_test_msg"
cat $_tmp_fn
echo -e "when doing a $_ping_cmd \\n"
echo -e "$_fix_msg\\n"
(( _failures++ ))
else
echo -e "$_test Passed testing $_ip $_test_msg"
fi
(( _test++ ))
} # end function ping_nic ()
function test_nic ()
{
#***********************************************************************
#* test each ip address found in the firs argument in _ck_nic_ary
#* decide if the ip is ipv4 or ipv6 and generate the required ping cmmand.
#***********************************************************************
set -- $(echo ${_ck_nic_ary[$_ix]}) # parse ck_nic_ary[$_ix]}
_ip=$1 # save first argument of string
shift # drop first argument
_test_msg=$* # save rest of string
_fix_msg=${_fix_msg_ary[$_ix]} # save repair/troubleshooting string
_ip=$(echo $_ip | tr -d '"') # strip double quotes from ip address
_count=$(echo $_ip | grep --count ':' ) # check for a :
if [ $_count -eq 0 ] ; then # its a ipv4 address
_ping_cmd="ping -c1 -w1 $_ip $_debug"
else
_ping_cmd="ping6 -c1 -w1 $_ip $_debug" # its an ipv6 ip
fi
ping_nic # run test on current ip
} # end function test_nic ()
#************************
#* main code start here
#************************
echo -e "\\n\tRunning $_exe\\n"
#*****************************************
#* check for no or multipal gateway values
#*****************************************
echo "$ route -n"
route -n
_count=$(route -n | grep --count ' UG ')
if [ $_count -ne 1 ] ; then
echo "
There is $_count gateway routes indicated in the above
where there should only be 1
"
fi
if [ "$_host_alias" = "localhost" ] ; then
echo "
Although it seems to not hurt your setup, you might consider
creating a Fully Qualified Domain (FQDN) name for your node.
Some applications will fail without one.
mysqld, postfix, sendmail, leafnode, dovecot,.. Usenet client
to name just a few. You may want to read
http://www.rfc-editor.org/rfc/rfc2606.txt
I suggest something like darkstar.home.test. Example locations:
\$ cat /etc/sysconfig/network
HOSTNAME=wb.home.test
NETWORKING=yes
CRDA_DOMAIN=US
\$ cat /etc/hostname
wb.home.test
NOTE: You will need to reboot system to make sure all apps
get notification about the new name
"
fi
echo " "
#********************
#* Now run all tests
#********************
for _ix in ${!_ck_nic_ary[*]} ; do # run all tests
let _test="$_ix + 1" # bump test counter
test_nic
done
_count=${#_ck_nic_ary[*]}
echo " "
for _dns in $_dns_isp ; do
(( _count++ ))
dig +short @$_dns
yahoo.com > /dev/null 2>&1
echo -n "Test ISP DNS server $_dns "
if [ $? -ne 0 ] ; then
(( _failures++ ))
echo "FAILED
ISP DNS server $_dns fails to resolve
yahoo.com.
Test used: dig +short @$_dns
yahoo.com
Check your router to verify that your ISP has not given you
new/different DNS server ip addresses.
Suggest re-booting router then check its DNS ip values.
If so, update _dns_isp= in $_exe with new values.
if not call your ISP help desk.
Workaround add nameserver 8.8.8.8
to bottom of /etc/resolvconf/resolv.conf.d/head.
Next network restart or reboot will update /etc/resolv.conf
"
fi
echo "Passed"
done
rm -f $_tmp_fn
echo -e "\\nTest totoal: $_count with $_failures failures \\n"
#***************** end network_ck ******************************************