I want to get the output only the interface which is down based on the configured interfaces in the network-scripts directory.
for i in $(ls -1 /etc/sysconfig/network-scripts/ifcfg-e*|sed 's/.*ifcfg-//g'); do grep -i 'down' /sys/class/net/$i/operstate; echo $i;done
How can I list only the interfaces which is down based on the input of the for iteration?
Thank you
2
Answers
Actually this one does the job:
I suggest with bash, its Parameter Expansion and CentOS 7 / RHEL 7:
${i#*-}
removes from stringifcfg-ens33
ifcfg-
to get only interface name.Update:
${i##*-}
removes from string/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-
to get only interface name.