LINUX Write a fully functional and professional looking script that meets all of
ID: 3849901 • Letter: L
Question
LINUX
Write a fully functional and professional looking script that meets all of the following requirements.
Resides within your ~/scripts directory and is named tps-report-gen.sh.
Take a supplied user's first name (Bob, Henry, or Frank) in any order when the script is executed (for example: sh tps-report-gen.sh bob).
Print out to the screen the text: TPS REPORT LISTING
A double newline.
Print out to the screen neatly the user’s name, company position, and home directory path on one line.
A double newline.
A list of TPS Reports associated with that user.
A double newline.
Print out to the screen the text: END REPORT LISTING
The script needs to print the output to the screen and generate a report into the same directory as the script named tps-list-USER-DATETIME.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 format the DATETIME portion as requested, use the following:
date "+%m%d%y%k%M" | awk -F" " {'print $1$2'}
Explanation / Answer
Script
-------------------------
#! /bin/sh
dd=$(date +"%m%d%y%k%M")
echo "TPS REPORT LISTING" >> "tps_list_$1_$dd.rpt"
new=$(pwd)
echo "$1,$2,$new" >> "tps_list_$1_$dd.rpt"
file="tps_list_$1_$dd.rpt"
echo $file
echo "END REPPORT LISTING" >> $file
Description
--------------------
1. Create a file with .sh extension.
2. Chnage the execute persmission using below command
chmod +777 <script-file-name.sh>
3. Execute the script using below command
tps-report-gen.sh bob cisco
4. The above command will create a file having extension .rpt and file name would be same as given in above query.
5. Check the contents of file.
Please let me know if you face any difficulties to make understanding on above code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.