Skip to content

Instantly share code, notes, and snippets.

@AGx10k
Last active June 2, 2021 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AGx10k/bebd6297c7d8a8bd856a55ad2f2393a5 to your computer and use it in GitHub Desktop.
Save AGx10k/bebd6297c7d8a8bd856a55ad2f2393a5 to your computer and use it in GitHub Desktop.
Hetzner hwdata + netdata
#!/bin/bash
w
echo
echo "Hardware data:"
echo
cpu_count="$(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)"
cpu_cores="$(cat /proc/cpuinfo | grep "siblings" | uniq | tr -d ' ' | cut -d: -f2)"
cpu_type="$(cat /proc/cpuinfo | grep "model name" | uniq | tr -s ' ' | cut -d: -f2)"
if [ "$cpu_count" -gt 0 ] ; then
for i in $(seq 1 $cpu_count) ; do
cpu_spec_type="$(echo "$cpu_type" | head -n$i | tail -n1)"
echo -n " CPU$i:$cpu_spec_type"
cpu_spec_cores="$(echo "$cpu_cores" | head -n$i | tail -n1)"
if [ "$cpu_spec_cores" -gt 1 ] ; then
echo " (Cores $cpu_spec_cores)"
else
echo
fi
done
else
echo " CPU: $cpu_type"
fi
ram=$(free -m | grep Mem: | tr -s ' ' | cut -d' ' -f2)
echo " Memory: $ram MB"
i=0
total=0
while read line; do
if [ -n "$line" ]; then
items=( $line )
drive="/dev/${items[3]}"
size=$((${items[2]} * 1024))
let total=total+$size
realsize=$size
si_size=$size
unit=''
while [ $si_size -gt 10000 ]; do
realsize=$[ $realsize / 1000 ]
si_size=$[ $si_size / 1024 ]
case "$unit" in
K) unit='M';;
M) unit='G';;
G) unit='T';;
*) unit='K';;
esac
done
echo -n " Disk $drive: $realsize ${unit}B (=> $si_size ${unit}iB) "
isempty=$(timeout 3 parted -m -s $drive print 2>&1 | grep unrecognised | cut -d ' ' -f 3-)
if [ -n "$isempty" ]; then
echo "doesn't contain a valid partition table"
else
echo ""
fi
let i=i+1
fi
done <<< "$(cat /proc/partitions | egrep "nvme[0-9]+n[0-9]$|[hsv]d[a-z]$" | sort -b -k 4 -V)"
if [ $total -gt 0 ]; then
unit=''
while [ $total -gt 10000 ]; do
total=$[ $total / 1024 ]
case "$unit" in
K) unit='M';;
M) unit='G';;
G) unit='T';;
*) unit='K';;
esac
done
echo -n " Total capacity $total ${unit}iB with $i Disk"
if [ $i -gt 1 ]; then
echo "s"
else
echo ""
fi
fi
raid="$(lspci | egrep "(3ware|Adaptec|LSI)" | cut -d ' ' -f2- | sed -e 's/bus controller: //' -e 's/(rev.*)//' -e 's/Inc //')"
[ "$raid" ] && echo " $raid"
echo
df -h | grep -e "Avail\|\/dev\/" | grep -v tmpfs
#!/bin/sh
# Network data Script by Jonas Keidel 2012
LANG=C
echo "Network data:"
for i in $(ifconfig -a | egrep '^eth.+|^en.+|^eno.+' | cut -d ':' -f 1); do
# detect link
link=$(ethtool $i | grep "Link detected" | tr -s ' ' | cut -d: -f2)
# get mac address
mac=$(ip link show dev $i | grep ether | tr -s ' ' | cut -d ' ' -f3)
# get ip address
ip=$(ip a show $i | grep -m1 inet | tr -s ' ' | cut -d' ' -f3 | cut -d/ -f1)
if [ -z "$ip" ] ; then
ip="(none)"
fi
ip6=$(ip a show $i | grep inet6 | grep -m1 global | awk '{print $2}')
if [ -z "$ip6" ] ; then
ip6="(none)"
fi
modul=$(ethtool -i $i | grep driver | tr -s ' ' | cut -d' ' -f2)
if [ -n "$modul" ] ; then
modul=$(modinfo -d $modul 2>/dev/null)
fi
printf " %-6s%s\n" "$i" "LINK:$link"
printf "%9s%s\n" " " "MAC: $mac"
printf "%9s%s\n" " " "IP: $ip"
printf "%9s%s\n" " " "IPv6: $ip6"
if [ -n "$modul" ] ; then
printf "%9s%s\n" " " "$modul"
fi
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment