0% found this document useful (0 votes)
34 views6 pages

CS212 FINALSLab Activty

This document contains details about scripts for a phone book application, including: 1. The main menu script "phmenu" which displays options to print, add, search, view, delete, edit employment status, and compute employment duration. 2. The "editemploymentstatus" script allows editing an employee's status between active, resigned, or retired. 3. The "computestatus" script computes an employee's active time by calculating the difference between their hire date and current date.

Uploaded by

2233357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

CS212 FINALSLab Activty

This document contains details about scripts for a phone book application, including: 1. The main menu script "phmenu" which displays options to print, add, search, view, delete, edit employment status, and compute employment duration. 2. The "editemploymentstatus" script allows editing an employee's status between active, resigned, or retired. 3. The "computestatus" script computes an employee's active time by calculating the difference between their hire date and current date.

Uploaded by

2233357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name: Roque, Rey Daniel L.

Class Code: 9343


Schedule: LEC 7:30 – 8:30 WS, LAB 9:00 – 10:30 WS
I. TEXTFILES
A. phmenu text file – Script containing the main menu of the phone book. It displays
the choices and runs the other scripts depending on which one you chose.
#! /bin/bash
#========================================================
# Script Name: phmenu
# By: Roque, Rey Daniel L.
# Date: 10/24/2023
# Purpose: A menu for the Corporate Phone List
# Command Line: phmenu
#========================================================
trap "rm ./f 2> /dev/null; exit"013
phonefile=~/source/corp_phones
loop=y
while test $loop = "y"
do
clear
tput cup 3 12; echo "Corporate Phone Reporting Menu"
tput cup 4 12; echo "=============================="
tput cup 6 9; echo "P - Print Phone List"
tput cup 7 9; echo "A - Add New Phones"
tput cup 8 9; echo "S - Search for Phones"
tput cup 9 9; echo "V - View Phone List"
tput cup 10 9; echo "D - Delete Phone"
tput cup 11 9; echo "ES - Edit Employment Status"
tput cup 12 9; echo "CER - Compute Employment Duration"
tput cup 14 9; echo "Q - Quit: "
tput cup 14 19;
read choice || continue
case $choice in
[Aa]) ./phoneadd ;;
[Pp]) ./phlist1 ;;
[Ss]) ./phonefind ;;
[Vv]) clear ; less $phonefile ;;
[Dd]) tput cup 16 4; echo "Delete Phone Record"
tput cup 17 4; echo "Phone: "
tput cup 17 11; read number
tput cup 18 4; echo "Accept? (y)es or (n)o: "
tput cup 18 27; read Accept
if test $Accept = "y"
then
sed /$number/d $phonefile > f
cp f $phonefile
rm f
fi
;;
ES) clear
./editemploymentstatus ;;
CER) clear
./computestatus ;;
[Qq]) clear ; exit ;;
*) tput cup 14 4; echo "Invalid Code"; read choice ;;\
esac
done

B. editemploymentstatus text file – script for editing an employee’s employment status


between ACTIVE, RESIGNED or RETIRED.
#!/bin/bash
#========================================================
# Script Name: editemploymentstatus
# By: Roque, Rey Daniel L.
# Date: 11/18/2023
# Purpose: Script that allows for editing an employee’s job status
# Command Line: editemploymentstatus
#========================================================

# File containing phonebook data


phonefile=~/source/corp_phones

# Function to display phonebook details


function display_details() {
echo "Phonebook Detail of $phone_number"
echo "Last Name: $last_name"
echo "First Name: $first_name"
echo "Middle Initial: $middle_initial"
echo "Dept# : $department_number"
echo "Job Title: $job_title"
echo "Date Hired: $date_hired"
echo "Job Status: $employment_status"
}

# Function to update employment status


function update_status() {
local valid_choices=("A" "B" "C")

read -p "Do you want to proceed? (Y/N): " proceed

while [[ ! "${proceed^^}" =~ ^(Y|N)$ ]]; do


read -p "Invalid choice. Please enter 'Y' or 'N': " proceed
done

if [ "${proceed^^}" == "Y" ]; then


read -p "Please enter the new status of this record:
A. RETIRED
B. RESIGNED
C. ACTIVE
CHOICE: " new_status

while [[ ! "${new_status^^}" =~ ^[ABC]$ ]]; do


read -p "Invalid choice. Please enter 'A', 'B', or 'C': " new_status
done

case "${new_status^^}" in
A)
employment_status="RETIRED"
echo "STATUS of $first_name $middle_initial $last_name changed
to RETIRED"
;;
B)
employment_status="RESIGNED"
echo "STATUS of $first_name $middle_initial $last_name changed
to RESIGNED"
;;
C)
employment_status="ACTIVE"
echo "STATUS of $first_name $middle_initial $last_name changed
to ACTIVE"
;;
*)
echo "Invalid choice. No changes made."
;;
esac
else
echo "No changes made."
fi
}
#Read phonebook file
read -p "Please enter the Phone Number : " phone_number
phonebook_entry=$(grep "$phone_number:" "$phonefile")
if [ ! -e "$phonefile" ]; then
echo "Phonebook file not found."
exit 1
fi

# Extract details from the entry


IFS=':' read -r phone_number last_name first_name middle_initial
department_number job_title date_hired employment_status <<<
"$phonebook_entry"

# Display details
display_details

# Update employment status


update_status
C. computestatus text file – script that computes an employee’s time duration within
their respective jobs.
#!/bin/bash
#========================================================
# Script Name: computestatus
# By: Roque, Rey Daniel L.
# Date: 11/18/2023
# Purpose: Script that allows for computing an employee’s active time in
their respective job.
# Command Line: editemploymentstatus
#========================================================

# File containing phonebook data


read -p "Please enter the Phone Number: " number
grep $number corp_phones | awk -F: '{printf "Phonebook Detail of
%s\nLast Name: %s\nFirst Name: %s\nMiddle Initial: %s\nDept# : %s\nJob
Title: %s\nDate Hired: %s\nJob Status: %s\n", $1, $2, $3, $4, $5, $6, $7,
$8}'
phone_details=$(grep $number corp_phones | awk -F: '{printf "%s", $8}')

if [ $phone_details == "RESIGNED" ] || [ $phone_details == "RETIRED" ];


then
echo "EMPLOYMENT DURATION"
echo "Sorry, this employee has already $phone_details."
else
date_started=$(grep $number corp_phones | awk -F: '{printf "%s", $7}')
current_date=$(date +'%Y-%m-%d')

start_seconds=$(date -d "$(echo $date_started | awk -F'-' '{printf "%s-%s-


%s", $3, $1, $2}')" +%s)
current_seconds=$(date -d "$current_date" +'%s')
duration_seconds=$((current_seconds - start_seconds))

years=$((duration_seconds / (365 * 24 * 3600)))


remainder=$((duration_seconds % (365 * 24 * 3600)))
months=$((remainder / (30 * 24 * 3600)))
remainder=$((remainder % (30 * 24 * 3600)))
days=$((remainder / (24 * 3600)))

echo "EMPLOYMENT DURATION"


echo "Number of Years: $years "
echo "Number of Months: $months"
echo "Number of Days: $days"
fi
II. SAMPLE RUNS
1. Running phmenu with the “./phmenu” command shows:

2. Edit Employment Status – option for editing an employee’s job status. You can
change it to three options:
A. Retired
B. Resigned
C. Active
After choosing, the script changes the job status for that employee accordingly.
3. Compute Employment Duration – this option shows how long employees have been
active within their respective jobs.

If the employee has the status RETIRED or RESIGNED, a message will be


prompted implying that they are no longer active.

You might also like