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

linux, virtualbox and centOS7 Create a custom banner that displays the following

ID: 3840402 • Letter: L

Question

linux, virtualbox and centOS7

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)

Note: after you make changes to ~/.bashrc and save the file and then use the command source ~/.bashrc to view the effects of the changes.

Explanation / Answer

echo command can be used to output a line of text.

To output an environmental variable (e.g. USER, HOSTNAME) enclose it within ${ and }. e.g. ${USER}

uptime command can be used to print system uptime (i.e. how long the system has been running).

ip route show command can be used to get interfaces and private / source IP address information.

grep command can be used to print lines containing given matching pattern (for instance lines with src).

awk command can be used to process lines of text and print requested information (for instance interface name and private IP address).

toupper command can be used to convert interface name to uppercase.

curl command can be used to print public IP address. Instead of ip.appspot.com I have used bot.whatismyipaddress.com as the former server seems to be overloaded when I tested.

Use above mentioned commands in ~/.bashrc to get required output on login.

File: ~/.bashrc

echo "Hello ${USER}"
echo "Welcome to ${HOSTNAME}"
uptime
ip route show | grep src | awk '{print "The IP address for "toupper($3)" is: "$9}'
#curl ip.appspot.com
curl bot.whatismyipaddress.com
echo ""

Sample output:

$ source ~/.bashrc

Hello user
Welcome to hostname
06:04:10 up 23 min, 1 user, load average: 1.03, 0.45, 0.45
The IP address for ETH0 is: 192.168.122.236
116.75.89.163