Week 3 assignment
Description
Begin by joining my github classroom using the following link. You will put your assignment submissions for each week into this repo.
After the repo has been forked to your account, you can then clone it and modify the files within it. You will begin by creating a script in the week3/assignment.sh
. This shell script has the following specifications.
- it expects 3 command-line arguments
- the first command-line argument should be the name of the machine that you are looking for
- the second should be the column that you would like to view
- The third column will be the URL that the script should use. It generally should be this for testing. * It is easiest to save these into global variables at the beginning of your script.
The script has the functions defined below. Note that none of the functions will take any parameters.
get_file
: this function will retrieve the supplied command line URL and save it to a location of your choice. Maybe/tmp/sample.txt
. Hint: usewget
. In my sample below, I turned off the output for wget. See if you can figure what thequiet
option does for wget by looking at the man page.get_column
: this function should print out the column for the machine indicated by the command-line arguments, from the file downloaded. This could be done with some usage ofgrep
andawk
. Depending on how you do this, the awk command could get kind of tricky. The hint 2 here may be useful. Make sure that you also remove the first two lines of the file since they are icky.show_output
: this function will call theget_column
function and will echo it out.main
: this function will callget_file
followed byget_column
followed byshow_output
.
You also need a call to the main
function. You should call it in this fashion:
# do not run main when sourcing the script
#[[ "$0" == "${BASH_SOURCE[0]}" ]] && main "$@" || true
main
A sample run of the script may be like follows:
joe@yavin:~/s23/it3110/scripts/bash/week1$ ./a1.sh clarke 2 https://it3110.cs.utahtech.edu/files/have_found.txt
b8:ac:6f:ab:91:1d
joe@yavin:~/s23/it3110/scripts/bash/week1$ ./a1.sh clarke 1 https://it3110.cs.utahtech.edu/files/have_found.txt
clarke
joe@yavin:~/s23/it3110/scripts/bash/week1$ ./a1.sh zinc 2 https://it3110.cs.utahtech.edu/files/have_found.txt
c8:2a:14:3f:a8:e0
Other additions to make to your script
You need to create a function called make_dhcp
. This function will display the appropriate fixed dhcp entry in the following format:
host bova {
hardware ethernet c4:2c:03:25:a2:22;
fixed-address 144.38.195.230;
}
Also, create another function called make_dns
. This function will display the appropriate DNS entry for this machine in the following format:
bova IN A 144.38.195.230
Note: there are tabs between each field in the above. There is also a newline at the end.
Make sure that your main
function is ONLY calling get_file
and get_column
.
Pass off
You should upload your script to the week3/assignment.sh
directory in github.
Last Updated 02/07/2025