Question

In: Computer Science

Fully Functional Script written in BASH In this section, you will write a fully functional script...

Fully Functional Script written in BASH

In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if you ran it multiple times per user). This script will be showcased to upper management and should demonstrate your best work.

Write the Script:

Write a fully functional and professional looking script that meets all of the following requirements.

1. Resides within your ~/scripts directory and is named tps-report-gen.sh.

2. Take a supplied user’s first name (Bob, Henry, or Frank) in any order when the script is executed (for example: sh tps-reportgen.sh bob).

3. Print out to the screen the text: TPS REPORT LISTING

4. A double newline.

5. Print out to the screen neatly the user’s name, company position, and home directory path on one line.

6. A double newline.

7. A list of TPS Reports associated with that user.

8. A double newline.

9. Print out to the screen the text: END REPORT LISTING

10. The script needs to print the output to the screen and generate a report into the same directory as the script named tps-list-USERDATETIME.rpt. USER would be the user's username and DATETIME would be the date and time that the report was run. USER and DATETIME would both change based on the username supplied and the date and time the script is executed. It may be easier to build the report file first, then simply cat the file to the screen within the script. An example report would look like:

tps-list-bob-030816624.rpt

HINT: To get the DATETIME portion formatted as requested use the following: date "+%m%d%y%k%M" | awk -F" " {'print $1$2'}

Solutions

Expert Solution

This Script generates the file(s) in the format described in the question. This also prints the listings on the screen using [printf "%s\n" tps-list-$1-*] where $1 is the argument passed (username) while executing the script.

---------------------------------------------------------------

BASH SCRIPT:

#!/bin/bash
echo "TPS REPORT LISTINGS"
echo "\n\n"

#Company Position and Directory Path
position="Manager"
dirpath="~/home/$1"

echo "User Name: $1, Company Position: $position, Home Directory Path: $dirpath"
echo "\n\n"

#Generate report (i.e. tps-list-bob-030816624.rpt)
d=$(date "+%m%d%y%k%M" | awk -F" " {'print $1$2'})
#Write something to file
cat <<EOF > "tps-list-"$1"-"$d".rpt"
Report Contents
EOF
echo "Report generated: tps-list-"$1"-"$d".rpt"

#List of TPS Reports associated with user $1
echo "List of TPS Reports Associated with User $1:"
printf "%s\n" tps-list-$1-*

echo "\n\n"
echo "END REPORT LISTING"

---------------------------------------------------------------

COMMAND USED: sh tps-report-gen.sh bob

OUTPUT: (This output is generated by running the same script many times so as to generate several reports)

TPS REPORT LISTINGS

User Name: bob, Company Position: Manager, Home Directory Path: ~/home/bob

Report generated: tps-list-bob-021617018.rpt
List of TPS Reports Associated with User bob:
tps-list-bob-021617006.rpt
tps-list-bob-021617007.rpt
tps-list-bob-021617008.rpt
tps-list-bob-021617009.rpt
tps-list-bob-021617011.rpt
tps-list-bob-021617016.rpt
tps-list-bob-021617017.rpt
tps-list-bob-021617018.rpt

END REPORT LISTING


Related Solutions

Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result. Submit your program as LastName_FirstName.sh file.
Write a bash script that will allow you to: Read in your Your name Course name...
Write a bash script that will allow you to: Read in your Your name Course name and Instructor’s name Then prompt the user to enter two numbers and determine which number is greater. Ex: If 10 is entered for the first number and 3 for the second, you should output Your name Course name Instructor’s name 10 is greater than 3. If 33 is entered for the first number and 100 for the second, you shou output Your name Course...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask the user to input the number of kilometers they need to travel. - Display the number of equivalent miles for the number. Use formula, Kilometers = miles/0.62137 - Every time the loop runs, it should ask the user if they want to continue, if user enters “Y” or “y”, then the loop runs again, if user enters “N” or “n”, then stop the loop...
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Write a bash script named q1f.sh that will edit the PATH environment variable to include the...
Write a bash script named q1f.sh that will edit the PATH environment variable to include the sourcefiles directory in your home directory and make the new variable global. Please show picture of output.
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of the default gateway on your machine (one way to get this is the 'default' entry, also shown as 0.0.0.0, in the output of 'ip route') and runs a ping (with a count of 5 pings) to it. Runs another count of 5 pings to the site example.com. Outputs a 1-line summary of interfaces on your machine, not including the loopback address (lo). Outputs a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT