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

Using Linux Create a custom banner that displays the following information when

ID: 3784758 • Letter: U

Question

Using Linux

Create a custom banner that displays the following information when you log into your normal user’s shell (hint: edit ~/.bashrc):

“Hello USER” – (make use of the USER environment variable to get the username)

“Welome to HOSTNAME” (make use of the HOSTNAME environment variable)

System uptime

System’s private IP addresses (not full blown ifconfig output, but just a line for each interface that says “The IP address for ETHX is: XXX.XXX.XXX.XXX” – hint: use the grep and awk commands)

Public IP address of the system, (hint use the curl command on ip.appspot.com)

Explanation / Answer

Hi,

copy these lines and paste it in the last line of your ~/.bashrc

echo HELLO $USER
echo WELCOME to $HOSTNAME
echo uptime | bash

for x in {1..10}
do
    p=$(ifconfig eth$x | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1;)
    echo "The IP Address for ETH$x is: $p"
done

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{print $2}'

explanation:
$USER and $HOSTNAME are hostnames we can directly echo them. uptime is a bash command we are executing it. The next one is printing private addresses, here I am assuming there were up to 10 of eth devices, ifconfig eth$x will give the device details of eth1,eth2...eth10. Then we are doing a grep with string "inet addr" which contains our ip address. Below is the sample output of it

          inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0

In order to format it, we are using cut. "cut -d ':'" means, -d for delimeter ':', it returns a list ['inet addr', '192.168.0.10 Bcast','192.168.0.255 Mask','255.255.255.0'] that splits with ':', so we need to index it (index starts from 1), so we are using -f 2, so we get "192.168.0.10 Bcast". Again we need to split by space, so we are using "cut -d ' '", it returns list ['192.168.0.10', ' '], in this we need to get by index 1. so, it becomes "cut -d ' ' -f 1".

To find the public IP address, we can use dig command that looksup google dns.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote