Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX 2) What command will search the file /tmp/MCSE for the pattern “MCSE”? (the

ID: 3769974 • Letter: U

Question

UNIX

2)   What command will search the file /tmp/MCSE for the pattern “MCSE”? (the file exists so you can test your command)

3)   Write a single command line that will change the permissions on your home directory so that you and members of your group can change into it, but others cannot.

4)   What command will show the amount of free disk space on the file systems attached to the server?

5)   Read the man page for tcpdump and provide the command and accompanying options required to read the file named /tmp/tcpdump.dmp, suppress name resolution(avoid DNS lookups), and print each packet in both hex and ASCII.

6)   Write a single command line that defines the variables N=444, M=555, O as the product (multiple) of N and M, and then echoes the value of O.

7)   Write a single command line that uses netstat and grep to count all connections in a state of “ESTABLISHED” and outputs a single number representing how many connections are currently open to the server.

8)   Write a short, interactive shell script that
a.   Asks the user for a numeric variable A
b.   Asks the user for a numeric variable B
c.   Echoes the text “A minus B equals:”
d.   Prints the value of a variable C which is A minus B

9)   Write a short, interactive shell script that:
a.   Asks the user to enter an IP address
b.   Performs a host lookup on the IP address and returns a name if available.
Note: I will test this using 72.14.204.104

10)   Write a short, interactive shell script that
a.   Asks the user to enter a host name (like www.google.com)
b.   Performs a traceroute on the host and then outputs a single line stating “The host %HOSTNAME is ____ Hops Away” where the ____ is the number of hops. (I will test this using www.google.com)

Explanation / Answer

Here is the list of unix commands for the question. For question 8 through 10, please put the answer for corresponding question in different file names ending with .sh. Example answer for question 8 can go into file question8.sh and then execute using

sh ./question8.sh

Please post a comment in case of any issues. Please rate the answer if it helped. Thank you very much.

2) grep "MCSE" /tmp/MCSE

======


3) chmod ug+x ~

=====

4) df -h

=====

5) tcpdump -n -XX -r /tmp/tcpdump.dmp
=====

6) N=444 && M=555 && O=`expr $N * $M` && echo $O
======

7) netstat -an | grep ESTABLISHED | wc -l

=======
8)

#!/bin/bash

read -p 'Enter a Number for variable A: ' A
read -p 'Enter a Number for variable B: ' B
C=`expr $A - $B`

echo 'A minus B equals:' $C
=========

9)

#!/bin/bash

read -p 'Enter an IP address: ' ipaddress

echo ""
echo "Performing host lookup ..."
nslookup $ipaddress

=========

10)

#!/bin/bash

read -p 'Enter a host name: ' hostname

echo ""
echo "Performing traceroute ..."
hops=`traceroute "$hostname" 2>/dev/null | tail -1 | awk '{print $1}'`
echo "The host $hostname is $hops Hops Away"