Welcome to the Linux Foundation Forum!

Shell Script Question

Hi all

I want u to help answer this question

( A shell script should be named new_database.sh and its purpose is to create a new database. It accepts two arguments, the first is SCHEMA_NAME and the second is a DATABASE_NAME. For instance, below is an example invocation of the new_database.sh script and response.

$ .new_database.sh persons tutors

DATABASE ‘tutors’ USING SCHEMA 'persons' HAS BEEN CREATED.

The name of the database and the schema it uses should be appended to the databases.txt file.

Below is an example databases.txt file:

databases.txt

tutors persons

student persons

nina_12345_grades grades

intel company

If either the SCHEMA_NAME does not exist or the DATABASE_NAME already exists, then you the command prints an appropriate error message and exit. If the SCHEMA_NAME exists and the DATABASE_NAME is not already used, then the script should append the information to the end of the databases.txt file, create a new empty database file of the form DATABASE_NAME.db, and print a message that the database has been created.

)

thank you.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 1,114
    And the question is?
  • Posts: 2,177
    Are you building your own text file based database or will this script be used with a database system like mysql or postgresql?

    Also can you please post the contents of your script so we can review your progress and recommend modifications?
  • here's a possible script skeleton. Copy the code below and paste into
    a script file. Fill in with your commands (database creation, etc.).
    1. #!/bin/sh
    2.  
    3. LOG=databases.txt
    4. usage()
    5. {
    6. cat <<END
    7. USAGE: $0 schema_name database_name
    8. provide description here
    9. END
    10. return 1
    11. }
    12. create_database()
    13. {
    14. #enter the commands to create the database
    15. if [ $? -eq 0 ]; then
    16. echo "created database $2 with schema $1"
    17. echo "$2 $1" >> $LOG
    18. return 0
    19. else
    20. echo "your error message here"
    21. return 1
    22. fi
    23. }
    24. #check number of arguments entered
    25. if [ $# -ne 2 ]; then
    26. usage
    27. exit $?
    28. fi
    29. create_database $1 $2

    You should probably use absolute path for the log file, eg
    1. LOG=$HOME/databases/databases.txt
    That way you could invoke the script from anywhere.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training