Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

linux, virtualbox and centOS7 Write a script in BASH that automatically writes your systems private (eth0) and public IP addresses to a file within your

linux, virtualbox and centOS7

Write a script in BASH that automatically writes your systems private (eth0) and public IP addresses to a file within your home directory called ipaddresses. The automatically generated ipaddresses file should contain the following information:

The date command must be used to provide a timestamp at the top of the file in the following format: Timestamp: (HH:MM) MMDDYYYY.

The next line should contain: ETH0 IP: XXX.XXX.XXX.XXX.

The last line should contain: Public IP: XXX.XXX.XXX.XXX.

The script should overwrite any current entries with the new entries, not append them to the file. Dont forget to change the permissions on the script so that it is executable! Setup a cron job to run the script every 30 mins, you can verify this works by checking the timestamp in the ipaddresses file to see if it is being updated correctly, make sure you let your VM run for a few hours during testing. Be sure to include a copy of your .bashrc file, a copy of your ipaddresses script and output file, and your cron job line in your lab report along with a description of how you set it up and what it means.

I cannot find eth0 when searching for IP, I need to use esp0s8. I tried the following without success, all I get are errors when executed. Any help would be appreciated.

#!/bin/bash

date=$(date +\(%R\)\"%m%d%Y\")

ip=$( ifconfig eth0 | sed -n '2p' | awk '{print $2}' | awk -F : '{print $2}' )

pubip=$(wget -qO- ipinfo.io/ip)

printf $date" "$ip" "$pubip" "i > ~/ip.info ;

#end

Save file in home directory by name "filename.sh" and change permission using following command:

"sudo chmod +x filename.sh"

The edit crontab using command : "crontab -e".

Content of crontab is as follows:

30 * * * * ~/filename.sh

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago