Question

Task 1 Write a shell program that uses the following snippets to collect usage information on the ethernet interface; •U...

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. $

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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>

Add a comment
Know the answer?
Add Answer to:
Task 1 Write a shell program that uses the following snippets to collect usage information on the ethernet interface; •U...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Edit, compile, and run the following programs on the UNIX shell: Write a program that takes...

    Edit, compile, and run the following programs on the UNIX shell: Write a program that takes in six commandline arguments and has four functions (described below) that use bitwise operators. The user should enter six space-separated commandline arguments: four characters (any ASCII character) followed by two integers. Anything else should print an error message telling the user what the correct input is and end the program. Convert the commandline input into "unsigned char" and "unsigned int" datatypes. Be careful with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT