Task 1 Write a shell program that uses the following snippets to collect usage information on the ethernet interface; •Use the output of the ifconfig command •Use the pipe symbol ‘|’ (usually Shift-\ above the Enter key) to send output text of one program to the input of the following program •Use grep to select the text for just the received and transmitted bytes on the network interface •Store the number of bytes in a shell variable Run the programs and select only the needed text with grep and sed; $ /sbin/ifconfig eth1 | grep "TX bytes" RX bytes:29786875464 (27.7 GiB) TX bytes:6537489909 (6.0 GiB) $ /sbin/ifconfig eth1 | grep "TX bytes" | sed -e "s/.*TX bytes://" | sed -e "s/(.*//" 6537490695 $ /sbin/ifconfig eth1 | grep "RX bytes" | sed -e "s/(.*//" | sed -e "s/.*://" 29786880658 Run the programs and capture the output to a shell variable; $ export tbytes=`/sbin/ifconfig eth1 | grep "TX bytes" | sed -e "s/.*TX bytes://" | sed -e "s/(.*//"` $ echo $tbytes 6537553143 Q) Can you produce the following output with your program, it should be in the following format; $ task1.sh Received 9999999 bytes, Transmitted 9999999 bytes. $
CODE :
#!/bin/bash
tbytes=`/sbin/ifconfig eth1 |grep "TX bytes"| sed -e 's/.*TX
bytes://' | sed -e 's/(.*//'`
rbytes=`/sbin/ifconfig eth1 |grep "RX bytes"| sed -e 's/.*RX
bytes://' | sed -e 's/(.*//'`
echo "Received: " $rbytes "Transmitted: " $tbytes
Output:
USER>sh ifconfig.sh
Received: 404582246 Transmitted: 4985744
USER>
Task 1 Write a shell program that uses the following snippets to collect usage information on the ethernet interface; •U...