Skip to content

antony@notes:~/ops-automation$ cat "chnameip.md"

chnameip

2022-08-07· ops-automation ·Shell Script

chnameip

$ cat /home/bigred/bin/chnameip
#!/bin/bash

ifn=$(lspci | grep Ethernet | wc -l)
[ "$ifn" -gt "1" ] && exit 0

cat /etc/network/interfaces | grep -e "^auto br0" &>/dev/null
[ "$?" == "0" ] && exit 0

cat /etc/network/interfaces | grep -e "^#keep" &>/dev/null
[ "$?" == "0" ] && exit 0

gw=$(route -n | grep -e "^0.0.0.0 ")
export GWIF=${gw##* }
ips=$(ifconfig $GWIF | grep 'inet ')
export IP=$(echo $ips | cut -d' ' -f2 | cut -d':' -f2)
export NETID=${IP%.*}
export GW=$(route -n | grep -e '^0.0.0.0' | tr -s \ - | cut -d ' ' -f2)

mac=$(cat /sys/class/net/eth0/address | cut -d':' -f5,6)
h=$(cat /home/bigred/bin/mactohost | grep "$mac" | cut -d ' ' -f2)

if [ "$h" != "" ]; then
bigred@alp:~$ sudo nano /etc/profile
bigred@alp:~$ bigred@alp:~$ sudo nano /etc/local.d/rc.local.start
bigred@alp:~$ bigred@alp:~$ sudo nano /etc/profile
bigred@alp:~$ cat /etc/local.d/rc.local.start
#!/bin/bash
gw=$(route -n | grep -e "^0.0.0.0 ")
export GWIF=${gw##* }
ips=$(ifconfig $GWIF | grep 'inet ')
export IP=$(echo $ips | cut -d' ' -f2 | cut -d':' -f2)
export NETID=${IP%.*}
export GW=$(route -n | grep -e '^0.0.0.0' | tr -s \ - | cut -d ' ' -f2)

echo "[System]" > /tmp/sinfo
echo "Hostname : `hostname`" >> /tmp/sinfo

m=$(free -mh | grep Mem: | tr -s ' ' | cut -d' ' -f2)
echo "Memory : ${m}M" >> /tmp/sinfo

cname=$(cat /proc/cpuinfo | grep 'model name' | head -n 1 | cut -d ':' -f2)
cnumber=$(cat /proc/cpuinfo | grep 'model name' | wc -l)
echo "CPU : $cname (core: $cnumber)" >> /tmp/sinfo

m=$(df -h | grep /dev/sda)
ds=$(echo $m | cut -d ' ' -f2)
echo "Disk : $ds" >> /tmp/sinfo

which kubectl &>/dev/null
if [ "$?" == "0" ]; then
   #v=$(kubectl version --short | head -n 1 | cut -d ":" -f2 | tr -d ' ')
   echo "Kubernetes: enabled" >> /tmp/sinfo
fi

echo "" >> /tmp/sinfo

echo "[Network]" >> /tmp/sinfo
echo "IP : $IP" >> /tmp/sinfo
echo "Gateway : $GW" >> /tmp/sinfo
cat /etc/resolv.conf | grep 'nameserver' | head -n 1 >> /tmp/sinfo

/bin/ping -c 1 www.hinet.net
[ "$?" == "0" ] && echo "Internet OK" >> /tmp/sinfo

modprobe tun
modprobe fuse
mount --make-rshared /
modprobe br_netfilter
modprobe ip_tables
tags: Shell Script