mirror of
https://github.com/smxi/inxi.git
synced 2025-01-31 10:02:18 +00:00
Finally figured out how those weird pseud multilevel arrays work, tried it with networking, and it's working, I can get
output for each line as an array of an array, so I can print and handle output better now.
This commit is contained in:
parent
f68dc801d4
commit
567a20af28
45
inxi
45
inxi
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
#### Script Name: inxi
|
||||
#### version: 0.3.9
|
||||
#### version: 0.3.10
|
||||
#### Date: November 3 2008
|
||||
########################################################################
|
||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||
|
@ -1224,7 +1224,8 @@ get_networking_data()
|
|||
gsub(/realtek semiconductor/, "Realtek", nic)
|
||||
gsub(/davicom semiconductor/, "Davicom", nic)
|
||||
gsub(/,/," ", nic)
|
||||
gsub(/'"$A_NORMAL_BANS"'/, "", nic); gsub(/ [ ]+/," ", nic); gsub(/^ +| +$/,"", nic)
|
||||
gsub(/'"$A_NORMAL_BANS"'/, "", nic)
|
||||
gsub(/ [ ]+/," ", nic); gsub(/^ +| +$/,"", nic)
|
||||
# The doublequotes above are necessary because of the pipes in the variable.
|
||||
eth[nic]++
|
||||
while (getline && !/^$/) {
|
||||
|
@ -1235,23 +1236,21 @@ get_networking_data()
|
|||
END {
|
||||
j=0
|
||||
for (i in eth) {
|
||||
usePorts=""
|
||||
if (eth[i]>1) {
|
||||
a[j]=eth[i]"x "i
|
||||
if (ports[i] != "") a[j]=a[j] " - At Port:" ports[i]
|
||||
if (ports[i] != "") {
|
||||
usePorts=ports[i]
|
||||
}
|
||||
}
|
||||
else {
|
||||
a[j]=i
|
||||
## note, some glitch in awk makes the second port number cut off if ENVIRON["C2"] is used
|
||||
## if (ports[i] != "") a[j]=a[j] ENVIRON["C1"] " At Port:" ENVIRON["C2"] ports[i]
|
||||
if (ports[i] != "") {
|
||||
a[j]=a[j] " - At Port:" ports[i]
|
||||
usePorts=ports[i]
|
||||
}
|
||||
}
|
||||
j++
|
||||
}
|
||||
j=0
|
||||
while (a[j]) {
|
||||
print a[j]
|
||||
# create array primary item for master array
|
||||
print a[j] "," usePorts
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
@ -1259,6 +1258,7 @@ get_networking_data()
|
|||
IFS="$ORIGINAL_IFS"
|
||||
}
|
||||
|
||||
|
||||
## return uptime string
|
||||
get_uptime()
|
||||
{
|
||||
|
@ -1440,21 +1440,38 @@ print_intro_data()
|
|||
|
||||
print_networking_data()
|
||||
{
|
||||
local i='' card_one='Card-1 ' network_data=''
|
||||
local i='' card_one='Card-1 ' network_data='' a_network_data='' port_data=''
|
||||
|
||||
# set A_NETWORK_DATA
|
||||
get_networking_data
|
||||
|
||||
IFS=","
|
||||
a_network_working=(${A_NETWORK_DATA[0]})
|
||||
IFS="$ORIGINAL_IFS"
|
||||
|
||||
if [[ -n ${A_NETWORK_DATA[@]} ]];then
|
||||
if [[ ${#A_NETWORK_DATA[@]} -le 1 ]];then
|
||||
card_one='Card '
|
||||
fi
|
||||
i=0
|
||||
network_data=$( create_print_line "Network:" "${C1}$card_one${C2}${A_NETWORK_DATA[i]}" )
|
||||
if [ -n "${a_network_working[1]}" ];then
|
||||
port_data=" ${C1}at port${C2} ${a_network_working[1]}"
|
||||
fi
|
||||
network_data="${C1}$card_one${C2}${a_network_working[0]}$port_data"
|
||||
network_data=$( create_print_line "Network:" "$network_data" )
|
||||
print_screen_output "$network_data"
|
||||
|
||||
while [[ -n ${A_NETWORK_DATA[++i]} ]]
|
||||
do
|
||||
network_data=$( create_print_line " " "${C1}Card-$(($i+1))${C2} ${A_NETWORK_DATA[i]}" )
|
||||
IFS=","
|
||||
a_network_working=( ${A_NETWORK_DATA[i]} )
|
||||
IFS="$ORIGINAL_IFS"
|
||||
port_data=''
|
||||
if [ -n "${a_network_working[1]}" ];then
|
||||
port_data=" ${C1}at port${C2} ${a_network_working[1]}"
|
||||
fi
|
||||
network_data="${C1}$card_one${C2}${a_network_working[0]}$port_data"
|
||||
network_data=$( create_print_line " " "$network_data" )
|
||||
print_screen_output "$network_data"
|
||||
done
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue