#!/bin/bash # # CIS 130 Lab 4 - myscript # # Rich Simms # Spring 2007 # # This script collects user information into a file named dbfile # # Usage: database # #debug="y" clear echo "Hello $(logname) on $(hostname)" echo " " echo "This program prompts you for information and" echo "and records it in a file named: dbfile" echo " " # Create dbfile if necessary if [[ -r dbfile ]]; then echo "(dbfile exists and will be appended)" else echo "(dbfile does not exist and will be created)" > dbfile fi echo " " echo -n "Please enter first name: " read answer if [ "$debug" = "y" ]; then echo "... trace answer = " $answer; fi if [ "$answer" = "" ]; then echo "OK, no more of this." exit 0 fi first=$answer echo -n "Please enter last name: " read answer if [ "$debug" = "y" ]; then echo "... trace answer = " $answer; fi if [ "$answer" = "" ]; then echo "OK, no more of this." exit 0 fi last=$answer echo -n "Please enter email address: " read answer if [ "$debug" = "y" ]; then echo "... trace answer = " $answer; fi if [ "$answer" = "" ]; then echo "OK, no more of this." exit 0 fi email=$answer echo -n "Please enter phone number as (###)###-####: " read answer if [ "$debug" = "y" ]; then echo "... trace answer = " $answer; fi if [ "$answer" = "" ]; then echo "OK, no more of this." exit 0 fi phone=$answer echo -n "Please enter 5-digit zip code: " read answer if [ "$debug" = "y" ]; then echo "... trace answer = " $answer; fi if [ "$answer" = "" ]; then echo "OK, no more of this." exit 0 fi zip=$answer # Append data to end of dbfile echo -e "$last\t$first\t$phone\t$email\t$zip" >> dbfile if [ "$debug" = "y" ]; then echo "dbfile listing:" cat dbfile fi # We are done echo "Success!" exit 0 /home/cis130/simmsric/lab4 $