Starting from:

$30

CS515-Assignment 8 Solved

In this assignment, you need to create some Shell Scripts in the linux environment. Using shell script one can write a series of commands in a plain text file. It is just like a batch file in MS-DOS but is more powerful than the MS-DOS batch file. Shell scripts are useful to automate some periodic maintenance activities, helps in creating new commands also it helps the system administrator to avoid writing the same set of commands again and again. To create a shell script, the basic steps are below-

•    Use any editor like vi to write shell script.

•    After writing the shell script, set execute permission for your script using chmod command. Example:

$ chmod +x your-script-name

$ chmod 755 your-script-name

•    To execute the shell script, following command can be used

$ ./your-script-name

Let’s consider the shell script uinfo.sh

#!/bib/bash

# a simple shell script to show some basic information clear echo "Hello $USER" echo "Today is " date echo "You are working in the directory" pwd

After saving the shell script, use the following command to change it to executable

$ chmod +x uinfo.sh

To execute the shell script, type the following

$ ./uinfo.sh

A sample output of the script is as follows-

Hello seed

Today is

Thur Mar 24 22 08:17:19 IST 2022

You are working in the directory

/home/seed/CS515

There are many good resources on shell script. Some of them are-

https://www.tutorialspoint.com/unix/shell_scripting.htm www.shellscript.sh

1           Tasks to be carried out
Create and initialize a simple text database. For this purpose, you need to create the following scripts.

•    Script1: createTable.sh will be used to create a CPI table (a text file). The script should accept a table name and some field names. Example - CPI.tab may represent a table for CPI records. It will contain, say three fields RollNo, Name and CPI.

•    Script2: insertRecord.sh will be used to insert records into the table. You need to provide a valid table name as one of the arguments. You can either insert one record at a time or you can insert multiple records using a single script2 invocation. You can use space as field separator.

•    Script3: updateRecord.sh will be used to update any field of the table. Use appropriate arguments for table name, field name, record number in the table and the new value using which the record will be updated.

1

2           General Guidelines
In each script, put some general comments like name of the developer, date of creation and the general purpose of the script. Put appropriate comment before each block of commands in the script. Exit with a status of zero when the script is able to correctly accomplish its task. Print an appropriate error message and exit with a nonzero status when the script is not able to accomplish its task.

3           Sample session
$ ./createTable.sh CPI.tab RollNo Name CPI

NEW TABLE ’CPI.tab’ WITH FIELDS ‘RollNo’, ‘Name’, ‘CPI’ CREATED

$ ./insertRecord.sh CPI.tab -r "2021CS01" -n "Ravi" -c 7.9

RECORD ADDED TO ’CPI.tab’ table with ’RollNo’ 2021CS01, ’Name’ Ravi and ’CPI’ 7.9

$ ./insertRecord.sh CPI.tab 3

Record 1

ENTER VALUES FOR RollNo: "2021CS02"

ENTER VALUES FOR Name: "Kiran"

ENTER VALUES FOR CPI: 8.0

Record 2

ENTER VALUES FOR RollNo: "2021CS03"

ENTER VALUES FOR Name: "Pranay"

ENTER VALUES FOR CPI: 8.4

Record 3

ENTER VALUES FOR RollNo: "2021CS04"

ENTER VALUES FOR Name: "Ali"

ENTER VALUES FOR CPI: 8.1

3 RECORDS ADDED TO ’CPI.tab’ relation

$ cat CPI.tab

RollNo Name CPI

2021CS01 Ravi 7.9

2021CS02 Kiran 8.0

2021CS03 Pranay 8.4

2021CS04 Ali 8.1

$ ./updateRecord.sh CPI.tab -r "2021CS04" CPI 8.7

RECORD WITH ROLLNO 2021CS04 IS UPDATED in ’CPI.tab’ table

$ cat CPI.tab

RollNo Name CPI

2021CS01 Ravi 7.9

2021CS02 Kiran 8.0

2021CS03 Pranay 8.4

2021CS04 Ali 8.7

More products