Computing.Net > Forums > Unix > help redoing unix script student db

help redoing unix script student db

Reply to Message Icon

Original Message
Name: Aremia
Date: June 13, 2003 at 00:21:55 Pacific
Subject: help redoing unix script student db
OS: windows 98
CPU/Ram: 500
Comment:



Hi,
I am trying to write a unix script for a student database program. I have some pieces of script for this database
that was left to me.

The main menu has options that brings their own menu options as you can see in the draft below.


MAIN MENU
(D)DISPLAY
(A)ADD
(E)EDIT
(S)SEARCH
(H)HELP
(E)EXIT

DISPLAY
(1)EXIT TO MAIN

EDIT
(1)EDIT
(2)DELETE
(3)EXIT TO MAIN
|
(1)NAME
(2)STUDENT ID
(3)CITY
(4)STATE
(5)MAJOR
(6)STATUS
(7)HELP
(8)EXIT


ADD
(1)NAME
(2)STUDENT ID
(3)CITY
(4)STATE
(5)MAJOR
(6)STATUS
(7)HELP
(8)EXIT

SEARCH
(1)SORT
(2)SEARCH
(3)EDIT
(4)HELP
(5)EXIT
|
(1)NAME
(2)STUDENT ID
(3)CITY
(4)STATE
(5)MAJOR
(6)STATUS
(7)HELP
(8)EXIT

HELP
(1)DISPLAY
(2)EDIT
(3)SEARCH

EXIT
EXIT TO MAIN


Main Menu
(1) Display Student Information (This option prompts user to enter student id #)
(2) Add Student (This option prompts user to enter student id #)
(3) Edit or Delete Student (This option prompts user to enter student id #)
(4) Report or Search
(5) Help
(6) Exit


Student Information
Name:
Student#:
City:
State:
Major:
GPA:
Status:
Hit Enter to view another student’s information.
(This will prompt user for another student id #)
Hit escape key to return to Main Menu
(This will return user to the Main Menu)


Add Student
This is not actually a menu. When option 2 is taken from the Main Menu, the user inputs the Student id #. The user is then prompted to enter student name, city, state, major, GPA, and status. The screen will also allow the user to display the information before accepting all of the data.

Edit or Delete Student
(1) Delete (This option will prompt the user with, “Are you sure you want to delete?”)
(2) Name Joe Smith
(3) City Denver
(4) State Colorado
(5) Major CIT
(6) Status Junior
(7) Exit (This will return the user to the Main Menu)


Report or Search
To query users by city or state, and maybe GPA, major and status.

Help
Each menu will have a help option to explain what type of data is required.

Exit
Self explanatory.

These files need up be uploaded to you current directory: main.ksh, display.ksh, edit.ksh, search.ksh, and all the *.help files.

To run this shell script, simply type this at the prompt: $ main.ksh

This is the script I have:

#!/bin/ksh
######HELP FOR EDIT SCREEN PART ONE (EDIT/DELETE) #################

echo "****USER MUST ENTER A VALID STUDENT ID TO EDIT****"
echo "EDIT - Will allow user to edit any fields in in the database:\n"
echo "Name, StudentID, City, State, Major, GPA, and Status\n"
echo "Name,City,State,Major and Status - Must not contain
alphanumeric\n"
echo "StudentID and GPA - Must Must be alphamueric, cannot be a
negative#\n"


#!/bin/ksh
PS3="Enter selection >"

#The is the EDIT/DELETE MODULE
##############################################################

##########The will prompt user for to Edit or
Delete####################################################
clear
while true
do
clear

echo "\t\tYou have chosen to Edit\Delete a student:\n"
echo "Select from the following options:\n"

###Give users choice to "EDIT" "DELETE" or "EXIT"

select Choice in "Edit Student" "Delete Student" "Help" "Exit to MAIN
MENU"

do
if [[ $Choice = @([DEH])* ]]
then
print " You selected option $REPLY: $Choice"

case $Choice in

###EDIT PART###
Edit*)

while true
do

###REMOVE UNWANTED FILES and output STDERR to junk if not found###

rm student.tmp 2> junk
rm student2.tmp 2> junk
rm student3.tmp 2> junk
rm student4.tmp 2> junk
#######################
rm id2.tmp 2> junk
rm id3.tmp 2> junk
rm id4.tmp 2> junk
#######################
rm city2.tmp 2> junk
rm city3.tmp 2> junk
rm city4.tmp 2> junk
#######################
rm state2.tmp 2> junk
rm state3.tmp 2> junk
rm state4.tmp 2> junk
#######################
rm major2.tmp 2> junk
rm major3.tmp 2> junk
rm major4.tmp 2> junk
#######################
rm gpa2.tmp 2> junk
rm gpa3.tmp 2> junk
rm gpa4.tmp 2> junk
#######################
rm status.tmp 2> junk
rm status.tmp 2> junk
rm status.tmp 2> junk
######################

###Capture STUDENT ID###

echo "Please enter student id, Enter to Exit:\c"
read student_id
clear

if [[ $student_id = "" ]]
then
clear
break 2
fi

###Test if student is in database####
#Student MUST be alphanumeric#

if [[ $student_id = [0-9]* ]]
then
grep ":$student_id:" student.data > student.tmp

####Test "student.tmp" file for content###

if test -s student.tmp
then
echo "\t ----- STUDENT INFORMATION -----\n"

###Print out Student Information if MATCH###
nawk 'BEGIN{FS=":";OFS=":"}{print $0}'\
student.tmp
echo

###Give users choice on which FIELD to Edit###

while true
do
select Field in Name Student# City State Major GPA Status Help
CANCEL
do
case $Field in

######### START EDIT NAME PART ###########
Na*)
name=$(nawk -F: '{print $1}' student.tmp)
clear
while true
do
echo "Current Name: $name"
echo "New Name:\c"
read new_name


###Name MUST be LETTERS###

if [[ $new_name = [A-Za-z]* ]]
then
echo "Name Change Successful!!!\n"


###Name EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$1 = "'"${new_name}"'"\
;print}' student.tmp >student2.tmp

grep -v ":$student_id:" student.data\
>student3.tmp

cat student3.tmp student2.tmp >> student4.tmp
cp student4.tmp student.data


###Print out NEW student NAME###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
student2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid Name enter by users###
else
echo "Invalid Name!!!"
continue

fi
done
;;

#########END OF NAME PART#################

######### START EDIT STUDENT ID PART ###########

Stu*)
id=$(nawk -F: '{print $2}' student.tmp)
clear
while true
do
echo "Current id: $id"
echo "New id:\c"
read new_id


###ID MUST be ALPHANUMERIC###

if [[ $new_id = [0-9]* ]]
then
echo "Name Change Successful!!!\n"


###ID EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$2 = "'"${new_id}"'"\
;print}' student.tmp >id2.tmp

grep -v ":$student_id:" student.data\
>id3.tmp

cat id3.tmp id2.tmp >> id4.tmp
cp id4.tmp student.data


###Print out NEW student ID###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
id2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid ID enter by users###
else
echo "Invalid ID!!!"
continue

fi
done
;;

######### END EDIT STUDENT STUDENT ID PART ###########

######### START EDIT STUDENT CITY PART ###########

Ci*)
city=$(nawk -F: '{print $3}' student.tmp)
clear
while true
do
echo "Current city: $city"
echo "New city:\c"
read new_city


###City MUST be LETTERS###

if [[ $new_city = [A-Za-z]* ]]
then
echo "City Change Successful!!!\n"


###City EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$3 = "'"${new_city}"'"\
;print}' student.tmp >city2.tmp

grep -v ":$student_id:" student.data\
>city3.tmp

cat city3.tmp city2.tmp >> city4.tmp
cp city4.tmp student.data


###Print out NEW student city###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
city2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid City enter by users###
else
echo "Invalid City Name!!!"
continue

fi
done
;;

#######################END OF CITY PART####################

######################START OF STATE PART##################

State*)
state=$(nawk -F: '{print $4}' student.tmp)
clear
while true
do
echo "Current state: $state"
echo "New state:\c"
read new_state


###State MUST be LETTERS###

if [[ $new_state = [A-Za-z]* ]]
then
echo "State Change Successful!!!\n"


###State EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$4 = "'"${new_state}"'"\
;print}' student.tmp >state2.tmp

grep -v ":$student_id:" student.data\
>state3.tmp

cat state3.tmp state2.tmp >> state4.tmp
cp state4.tmp student.data


###Print out NEW student state###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
state2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid state enter by users###
else
echo "Invalid state Name!!!"
continue

fi
done
;;

##################END OF STATE PART######################

#################START OF MAJOR PART###################

Major*)
major=$(nawk -F: '{print $5}' student.tmp)
clear
while true
do
echo "Current major: $major"
echo "New major:\c"
read new_major


###Major MUST be LETTERS###

if [[ $new_major = [A-Za-z]* ]]
then
echo "Major Change Successful!!!\n"


###Major EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$5 = "'"${new_major}"'"\
;print}' student.tmp >major2.tmp

grep -v ":$student_id:" student.data\
>major3.tmp

cat major3.tmp major2.tmp >> major4.tmp
cp major4.tmp student.data


###Print out NEW student major###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
major2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid major enter by users###
else
echo "Invalid Major Name!!!"
continue

fi
done
;;

####################END OF MAJOR PART#######################

###################START OF GPA PART########################

GPA*)
gpa=$(nawk -F: '{print $6}' student.tmp)
clear
while true
do
echo "Current GPA: $gpa"
echo "New GPA:\c"
read new_gpa


###GPA MUST be LETTERS###

if [[ $new_gpa = [0-9]* ]]
then
echo "GPA Change Successful!!!\n"


###GPA EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$6 = "'"${new_gpa}"'"\
;print}' student.tmp >gpa2.tmp

grep -v ":$student_id:" student.data\
>gpa3.tmp

cat gpa3.tmp gpa2.tmp >> gpa4.tmp
cp gpa4.tmp student.data


###Print out NEW GPA ###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
gpa2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid GPA enter by users###
else
echo "Invalid GPA!!!"
continue

fi
done
;;

####################END OF GPA PART#######################

####################START OF STATUS PART##################

Status*)
status=$(nawk -F: '{print $7}' student.tmp)
clear
while true
do
echo "Current Status: $status"
echo "New Status:\c"
read new_status


###status MUST be LETTERS###

if [[ $new_status = [A-Za-z]* ]]
then
echo "Status Change Successful!!!\n"


###status EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$7 = "'"${new_status}"'"\
;print}' student.tmp >status2.tmp

grep -v ":$student_id:" student.data\
>status3.tmp

cat status3.tmp status2.tmp >> status4.tmp
cp status4.tmp student.data


###Print out NEW status ###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
status2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid status enter by users###
else
echo "Invalid Status!!!"
continue

fi
done
;;

####################END OF STATUS PART####################

He*)
echo
echo
edit1.help
echo "***Press ENTER to continue***\n";read
clear
continue 2
;;

CA*)
break 4
clear
;;

*)
echo "Invalid Choice"
break 4
clear

;;


##########################################################
esac
done
done

###ERROR Checking for student id NOT in DATABASE###

else
echo "$student_id Number does not Exit!"
continue

fi

###ERROR Checking for invalid student id###

else
echo "$student_id is an invalid student number!"
continue

fi

done
;;

###DELETE PART##################################################
Del*)

while true
do


rm delete.tmp 2> junk
rm delete2.tmp 2> junk
rm delete3.tmp 2> junk

###Capture student id###

echo "Please enter student id, Enter to Exit:\c"
read student_id
clear

if [[ $student_id = "" ]]
then
clear
break 2
fi

###Test if studentid is in database####

if [[ $student_id = [0-9]* ]]
then
grep ":$student_id:" student.data > delete.tmp

###DELETE SCRIPT PART###

if test -s delete.tmp
then
grep -v ":$student_id:" student.data > delete3.tmp

cp delete3.tmp student.data

echo "Delete Successful!!!"

cat student.data

break

###ERROR Checking###

else
echo "Student Number does not Exit"
continue
fi

###ERROR Checking###

else
echo " $student_id is an invalid student number! "
continue
fi
done
;;

###EXIT PART#################################

He*)
echo
echo
edit.help
echo "***Press ENTER to continue***\n";read
clear
continue 2

;;

Ex*)
break 5
clear
;;

esac

else
print "$REPLY: Invalid choice!"
continue
clear

fi

done
done

clear
main.ksh


#!/bin/ksh
######HELP FOR EDIT SCREEN PART TWO (EDIT/DELETE)#################
echo
echo "Name -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid Name" and prompt user to enter a valid
name\n"
echo "Student ID -"Must be Numeric" If a letter is entered, the user
will
get"
echo "an error message "Invalid Student ID" and prompt user to enter a
valid
student id\n"
echo "City -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid City" and prompt user to enter a valid
city\n"
echo "State -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid State" and prompt user to enter a valid
State\n"
echo "Major -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid Major" and prompt user to enter a valid
Major\n"
echo "GPA-"Must be letters" If a number is entered, the user will get"
echo "an error message "Invalid GPA" and prompt user to enter a valid
GPA\n"
echo "CANCEL -Cancel the change and return to the selection menu"
Would you tell me what pieces should of script I need to write (menus variable, loops, etc) and how do I connect them with this script ?
I think we also need the file student.data I put 3 students information for testing purposes.
student.data
Jim Goff 256128963 Denver CO MGMT 2.9 Freshman
John Smith 9393939 Denver CO CIT 3.99 Junior
Tom Bailey 555892345 Denver CO FNCE 3.5 Junior

Thanks in advance
Aremia



Main Menu
(1) Display Student Information (This option prompts user to enter student id #)
(2) Add Student (This option prompts user to enter student id #)
(3) Edit or Delete Student (This option prompts user to enter student id #)
(4) Report or Search
(5) Help
(6) Exit


Student Information
Name:
Student#:
City:
State:
Major:
GPA:
Status:
Hit Enter to view another student’s information.
(This will prompt user for another student id #)
Hit escape key to return to Main Menu
(This will return user to the Main Menu)


Add Student
This is not actually a menu. When option 2 is taken from the Main Menu, the user inputs the Student id #. The user is then prompted to enter student name, city, state, major, GPA, and status. The screen will also allow the user to display the information before accepting all of the data.

Edit or Delete Student
(1) Delete (This option will prompt the user with, “Are you sure you want to delete?”)
(2) Name Joe Smith
(3) City Denver
(4) State Colorado
(5) Major CIT
(6) Status Junior
(7) Exit (This will return the user to the Main Menu)


Report or Search
To query users by city or state, and maybe GPA, major and status.

Help
Each menu will have a help option to explain what type of data is required.

Exit
Self explanatory.

These files need up be uploaded to you current directory: main.ksh, display.ksh, edit.ksh, search.ksh, and all the *.help files.

To run this shell script, simply type this at the prompt: $ main.ksh

This is the script I have:

#!/bin/ksh
######HELP FOR EDIT SCREEN PART ONE (EDIT/DELETE) #################

echo "****USER MUST ENTER A VALID STUDENT ID TO EDIT****"
echo "EDIT - Will allow user to edit any fields in in the database:\n"
echo "Name, StudentID, City, State, Major, GPA, and Status\n"
echo "Name,City,State,Major and Status - Must not contain
alphanumeric\n"
echo "StudentID and GPA - Must Must be alphamueric, cannot be a
negative#\n"


#!/bin/ksh
PS3="Enter selection >"

#The is the EDIT/DELETE MODULE
##############################################################

##########The will prompt user for to Edit or
Delete####################################################
clear
while true
do
clear

echo "\t\tYou have chosen to Edit\Delete a student:\n"
echo "Select from the following options:\n"

###Give users choice to "EDIT" "DELETE" or "EXIT"

select Choice in "Edit Student" "Delete Student" "Help" "Exit to MAIN
MENU"

do
if [[ $Choice = @([DEH])* ]]
then
print " You selected option $REPLY: $Choice"

case $Choice in

###EDIT PART###
Edit*)

while true
do

###REMOVE UNWANTED FILES and output STDERR to junk if not found###

rm student.tmp 2> junk
rm student2.tmp 2> junk
rm student3.tmp 2> junk
rm student4.tmp 2> junk
#######################
rm id2.tmp 2> junk
rm id3.tmp 2> junk
rm id4.tmp 2> junk
#######################
rm city2.tmp 2> junk
rm city3.tmp 2> junk
rm city4.tmp 2> junk
#######################
rm state2.tmp 2> junk
rm state3.tmp 2> junk
rm state4.tmp 2> junk
#######################
rm major2.tmp 2> junk
rm major3.tmp 2> junk
rm major4.tmp 2> junk
#######################
rm gpa2.tmp 2> junk
rm gpa3.tmp 2> junk
rm gpa4.tmp 2> junk
#######################
rm status.tmp 2> junk
rm status.tmp 2> junk
rm status.tmp 2> junk
######################

###Capture STUDENT ID###

echo "Please enter student id, Enter to Exit:\c"
read student_id
clear

if [[ $student_id = "" ]]
then
clear
break 2
fi

###Test if student is in database####
#Student MUST be alphanumeric#

if [[ $student_id = [0-9]* ]]
then
grep ":$student_id:" student.data > student.tmp

####Test "student.tmp" file for content###

if test -s student.tmp
then
echo "\t ----- STUDENT INFORMATION -----\n"

###Print out Student Information if MATCH###
nawk 'BEGIN{FS=":";OFS=":"}{print $0}'\
student.tmp
echo

###Give users choice on which FIELD to Edit###

while true
do
select Field in Name Student# City State Major GPA Status Help
CANCEL
do
case $Field in

######### START EDIT NAME PART ###########
Na*)
name=$(nawk -F: '{print $1}' student.tmp)
clear
while true
do
echo "Current Name: $name"
echo "New Name:\c"
read new_name


###Name MUST be LETTERS###

if [[ $new_name = [A-Za-z]* ]]
then
echo "Name Change Successful!!!\n"


###Name EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$1 = "'"${new_name}"'"\
;print}' student.tmp >student2.tmp

grep -v ":$student_id:" student.data\
>student3.tmp

cat student3.tmp student2.tmp >> student4.tmp
cp student4.tmp student.data


###Print out NEW student NAME###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
student2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid Name enter by users###
else
echo "Invalid Name!!!"
continue

fi
done
;;

#########END OF NAME PART#################

######### START EDIT STUDENT ID PART ###########

Stu*)
id=$(nawk -F: '{print $2}' student.tmp)
clear
while true
do
echo "Current id: $id"
echo "New id:\c"
read new_id


###ID MUST be ALPHANUMERIC###

if [[ $new_id = [0-9]* ]]
then
echo "Name Change Successful!!!\n"


###ID EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$2 = "'"${new_id}"'"\
;print}' student.tmp >id2.tmp

grep -v ":$student_id:" student.data\
>id3.tmp

cat id3.tmp id2.tmp >> id4.tmp
cp id4.tmp student.data


###Print out NEW student ID###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
id2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid ID enter by users###
else
echo "Invalid ID!!!"
continue

fi
done
;;

######### END EDIT STUDENT STUDENT ID PART ###########

######### START EDIT STUDENT CITY PART ###########

Ci*)
city=$(nawk -F: '{print $3}' student.tmp)
clear
while true
do
echo "Current city: $city"
echo "New city:\c"
read new_city


###City MUST be LETTERS###

if [[ $new_city = [A-Za-z]* ]]
then
echo "City Change Successful!!!\n"


###City EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$3 = "'"${new_city}"'"\
;print}' student.tmp >city2.tmp

grep -v ":$student_id:" student.data\
>city3.tmp

cat city3.tmp city2.tmp >> city4.tmp
cp city4.tmp student.data


###Print out NEW student city###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
city2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid City enter by users###
else
echo "Invalid City Name!!!"
continue

fi
done
;;

#######################END OF CITY PART####################

######################START OF STATE PART##################

State*)
state=$(nawk -F: '{print $4}' student.tmp)
clear
while true
do
echo "Current state: $state"
echo "New state:\c"
read new_state


###State MUST be LETTERS###

if [[ $new_state = [A-Za-z]* ]]
then
echo "State Change Successful!!!\n"


###State EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$4 = "'"${new_state}"'"\
;print}' student.tmp >state2.tmp

grep -v ":$student_id:" student.data\
>state3.tmp

cat state3.tmp state2.tmp >> state4.tmp
cp state4.tmp student.data


###Print out NEW student state###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
state2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid state enter by users###
else
echo "Invalid state Name!!!"
continue

fi
done
;;

##################END OF STATE PART######################

#################START OF MAJOR PART###################

Major*)
major=$(nawk -F: '{print $5}' student.tmp)
clear
while true
do
echo "Current major: $major"
echo "New major:\c"
read new_major


###Major MUST be LETTERS###

if [[ $new_major = [A-Za-z]* ]]
then
echo "Major Change Successful!!!\n"


###Major EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$5 = "'"${new_major}"'"\
;print}' student.tmp >major2.tmp

grep -v ":$student_id:" student.data\
>major3.tmp

cat major3.tmp major2.tmp >> major4.tmp
cp major4.tmp student.data


###Print out NEW student major###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
major2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid major enter by users###
else
echo "Invalid Major Name!!!"
continue

fi
done
;;

####################END OF MAJOR PART#######################

###################START OF GPA PART########################

GPA*)
gpa=$(nawk -F: '{print $6}' student.tmp)
clear
while true
do
echo "Current GPA: $gpa"
echo "New GPA:\c"
read new_gpa


###GPA MUST be LETTERS###

if [[ $new_gpa = [0-9]* ]]
then
echo "GPA Change Successful!!!\n"


###GPA EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$6 = "'"${new_gpa}"'"\
;print}' student.tmp >gpa2.tmp

grep -v ":$student_id:" student.data\
>gpa3.tmp

cat gpa3.tmp gpa2.tmp >> gpa4.tmp
cp gpa4.tmp student.data


###Print out NEW GPA ###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
gpa2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid GPA enter by users###
else
echo "Invalid GPA!!!"
continue

fi
done
;;

####################END OF GPA PART#######################

####################START OF STATUS PART##################

Status*)
status=$(nawk -F: '{print $7}' student.tmp)
clear
while true
do
echo "Current Status: $status"
echo "New Status:\c"
read new_status


###status MUST be LETTERS###

if [[ $new_status = [A-Za-z]* ]]
then
echo "Status Change Successful!!!\n"


###status EDIT script BEGIN###

nawk 'BEGIN{FS=":";OFS=":"}{$7 = "'"${new_status}"'"\
;print}' student.tmp >status2.tmp

grep -v ":$student_id:" student.data\
>status3.tmp

cat status3.tmp status2.tmp >> status4.tmp
cp status4.tmp student.data


###Print out NEW status ###

nawk 'BEGIN{FS=":";OFS=":"}{$2~/'^"${student_id}"$'/}\
{print $0}'\
status2.tmp

echo
echo "*** Press ENTER to continue ***\n";read $pause
clear
break 5

###ERROR Checking for Invalid status enter by users###
else
echo "Invalid Status!!!"
continue

fi
done
;;

####################END OF STATUS PART####################

He*)
echo
echo
edit1.help
echo "***Press ENTER to continue***\n";read
clear
continue 2
;;

CA*)
break 4
clear
;;

*)
echo "Invalid Choice"
break 4
clear

;;


##########################################################
esac
done
done

###ERROR Checking for student id NOT in DATABASE###

else
echo "$student_id Number does not Exit!"
continue

fi

###ERROR Checking for invalid student id###

else
echo "$student_id is an invalid student number!"
continue

fi

done
;;

###DELETE PART##################################################
Del*)

while true
do


rm delete.tmp 2> junk
rm delete2.tmp 2> junk
rm delete3.tmp 2> junk

###Capture student id###

echo "Please enter student id, Enter to Exit:\c"
read student_id
clear

if [[ $student_id = "" ]]
then
clear
break 2
fi

###Test if studentid is in database####

if [[ $student_id = [0-9]* ]]
then
grep ":$student_id:" student.data > delete.tmp

###DELETE SCRIPT PART###

if test -s delete.tmp
then
grep -v ":$student_id:" student.data > delete3.tmp

cp delete3.tmp student.data

echo "Delete Successful!!!"

cat student.data

break

###ERROR Checking###

else
echo "Student Number does not Exit"
continue
fi

###ERROR Checking###

else
echo " $student_id is an invalid student number! "
continue
fi
done
;;

###EXIT PART#################################

He*)
echo
echo
edit.help
echo "***Press ENTER to continue***\n";read
clear
continue 2

;;

Ex*)
break 5
clear
;;

esac

else
print "$REPLY: Invalid choice!"
continue
clear

fi

done
done

clear
main.ksh


#!/bin/ksh
######HELP FOR EDIT SCREEN PART TWO (EDIT/DELETE)#################
echo
echo "Name -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid Name" and prompt user to enter a valid
name\n"
echo "Student ID -"Must be Numeric" If a letter is entered, the user
will
get"
echo "an error message "Invalid Student ID" and prompt user to enter a
valid
student id\n"
echo "City -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid City" and prompt user to enter a valid
city\n"
echo "State -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid State" and prompt user to enter a valid
State\n"
echo "Major -"Must be letters" If a number is entered, the user will
get"
echo "an error message "Invalid Major" and prompt user to enter a valid
Major\n"
echo "GPA-"Must be letters" If a number is entered, the user will get"
echo "an error message "Invalid GPA" and prompt user to enter a valid
GPA\n"
echo "CANCEL -Cancel the change and return to the selection menu"
Would you tell me what pieces should of script I need to write (menus variable, loops, etc) and how do I connect them with this script ?
I think we also need the file student.data I put 3 students information for testing purposes.
student.data
Jim Goff 256128963 Denver CO MGMT 2.9 Freshman
John Smith 9393939 Denver CO CIT 3.99 Junior
Tom Bailey 555892345 Denver CO FNCE 3.5 Junior

Thanks in advance
Aremia




Report Offensive Message For Removal


Response Number 1
Name: WilliamRobertson
Date: June 13, 2003 at 06:00:27 Pacific
Reply: (edit)

Is there some part of this you are having trouble with?

commands 2>junk
writes an actual file named "junk". The usual practice for discarding error output is

commands 2>/dev/null

or

commands 2>&-


Report Offensive Follow Up For Removal

Response Number 2
Name: Aremia
Date: June 13, 2003 at 23:43:04 Pacific
Reply: (edit)

My main problem with this script is that I couldn't make it run the way it is. I believe because is missing a few menu options. I am trying to complete it.
I wrote a Main Menu for this (the script that I sent yesterday wasn't written by me)
Well I am trying to tie my Main Menu to this script.
For instance if the user go to the Main Menu and choose to Edit, then screen will display a menu options and prompt for a selection. Once the user selects the option other menu option will display. That's is the part I am not sure about. I see the script use case, while and ifs. I need some advice in how to start tying (binding) the submenus from the Main Menu to have this program run as expected.
All your replies are appreciated.
I need help


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: help redoing unix script student db

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge