summaryrefslogtreecommitdiff
path: root/scripts/eth.sh
blob: f4c1388fe27de17119a18974ef9b2feea30cc3e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
# dotfiles -- scripts/eth.sh
# author: johannst

if="${BLOCK_INSTANCE:-enp0s25}"
[[ ! -d /sys/class/net/${if} ]] && exit 0

# operstate: down, up
[[ "$(cat /sys/class/net/$if/operstate)" = 'down' ]] && exit 0

# first ipv4 addr
IP_ADDR=$(ip address show $if | grep 'inet ' | sed 's/\s\+inet \([0-9.]\+\)\/.*/\1/')

echo "$IP_ADDR"