#!/usr/bin/ksh # # # Initially, I will support searchs on owner, vendor and readme # They will return the following fields # id, vendor, format, owner, keyword, readme, map # # these are the following fields and types for the # tape database # # id=char16, # vendor=char16, # density=int4, # format=char16, # owner=char16, # date=abstime, # creator=char16, # archival=bool, # oldid=int4, # oldreadme=text, # keyword=text, # readme=text, # map=text, # old_density=int4, # old_c=text, # old_date=abstime, # old_format=char16, # old_vendor=char16, # old_readme=text, # old_location=text, # old_tapenumber=int4, # old_owner=char16, # old_p=int4, # old_q=int4, # old_record=int4, # old_satellite=char16, # old_time=char16 DBOWNER="miley" SCRIPTFILE="/tmp/p_runit" ENTRY="/tmp/PG_entry" DB="FOOMILEY" search_choice="~" dbn="LIST" tape_fields="word def" default_fields="$dbn.word, $dbn.def" LAST_FIELD=${tape_fields##* } function mod_the_database { rm $ENTRY print -n "Enter word:" read word print "retrieve ($dbn.all) where ($dbn.word = \"$word\")\g\q\n" > $ENTRY monitor $DB < $ENTRY newlist="$tape_fields" rm $ENTRY choice=${newlist%% *} print "Enter value for update or for no update\n" print "replace $dbn ( \n" >> $ENTRY while [[ $choice != "" ]] do print -n "Enter update for $choice:" read n_input tmp=${newlist#* } newlist=$tmp if [[ $n_input != "" ]] then print -n "$choice=\"$n_input\"" >> $ENTRY fi if [[ $choice = $LAST_FIELD ]] then print ")\n where ($dbn.word = \"$word\") \g\n" >> $ENTRY break elif [[ $n_input != "" ]] then print ",\n" >> $ENTRY fi choice=${newlist%% *} done monitor $DB < $ENTRY } function search_the_database { menu_list="word def" clear select database_choice in $menu_list do text_search # call the appropriate routine break done } function text_search { print "\nText Search Operator\n" print -n "Echo string to match:\t" read search_string print "retrieve ( $default_fields ) where ( $dbn.$database_choice $search_choice \"$search_string\" ) \g\n \q \n" > $SCRIPTFILE monitor $DB < $SCRIPTFILE } function type_help { print "Help Menu on Search Types" print '~\ta~b\t\tcontains string a in text b' print '=\ta=b\t\ta equals b' } function add_to_database { newlist="$tape_fields " rm $ENTRY print "append $dbn ( \n" >> $ENTRY choice=${newlist%% *} while [[ $choice != "" ]] do print -n "Enter value for $choice:" read n_input tmp=${newlist#* } newlist=$tmp print "$choice=\"$n_input\"" >> $ENTRY if [[ $choice = $LAST_FIELD ]] then print ")\n \g\n\q\n" >> $ENTRY else print "," >> $ENTRY fi choice=${newlist%% *} done monitor $DB < $ENTRY } ######################################################333 print "Welcome to the interface to postgres' monitor program\n" print "This script is customized to add entries and search\n" print "the tapelist database for entries\n" sleep 3 PS3="Enter the number for your choice: or for new menu " #database_choice="id owner format readme tapemap all" #echo $database_choice clear select menu_list in "Add Entry to Database" "Search Database" "Modify Entry in Database" "quit" do case $menu_list in "Add Entry to Database") add_to_database;; "Modify Entry in Database") mod_the_database;; "Search Database") search_the_database ;; "quit") break;; *) print "You have entered an invalid entry, try again\n" esac done