Question : Grep command

Hello,

Iam trying to write a small Bash script with look for the "eth" and subsequently, it should look for the string "UP" as shown in the below output. If it found the match, the script should continue to next stage or else it should display the error message saying "ethX interface is down" (where 'X' is the interface number). Please help me, this is urgent for me. Thanks in advance.

eth4      Link encap:Ethernet  HWaddr 00:15:17:9C:11:A5
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:432872853 errors:0 dropped:0 overruns:0 frame:0
          TX packets:313656456 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:587346118664 (547.0 GiB)  TX bytes:149503575836 (139.2 GiB)
          Interrupt:82 Memory:f2000000-f2012100

eth5      Link encap:Ethernet  HWaddr 00:21:5E:36:21:96
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::221:5eff:fe36:2196/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:141480 errors:0 dropped:0 overruns:0 frame:0
          TX packets:142977 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:36258160 (34.5 MiB)  TX bytes:37118470 (35.3 MiB)
          Interrupt:209 Memory:f4000000-f4012100


Thanks,
AR

Answer : Grep command

1:
2:
3:
4:
5:
6:
7:
#!/bin/sh
 
INTERFACES=`ifconfig -a | awk '/^eth/ {print $1}'`
 
for int in ${INTERFACES}; do
        ifconfig ${int} | grep -q UP || echo ${int} interface is down.
done
Open in New Window Select All
Random Solutions  
 
programming4us programming4us