Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with UNIX on bash shell. This is the a3p1task2.c i have made for it #include #include int main(int argc, char* argv[]) { sqlite3 *db;

Help with UNIX on bash shell.

This is the a3p1task2.c i have made for it

#include #include

int main(int argc, char* argv[]) { sqlite3 *db; char *zErrMsg = 0; int rc;

rc = sqlite3_open("test.db", &db);

if( rc ) { fprintf(stderr, "Can't open database: %s ", sqlite3_errmsg(db)); return(0); } else { fprintf(stderr, "Opened database successfully "); } sqlite3_close(db); }

Task #1.

Create a sqlite3 database (called mypasswd) and create a table (passwd) to load the passwd information from /etc/passwd file as shown below.

{cleacslinux1:~/sqlite/passwd} sqlite3 mypasswd

SQLite version 3.14.1 2016-08-11 18:53:32

Enter ".help" for usage hints.

sqlite> create table pwtable (user, pass, uid, gid, gecos, home, shell);

sqlite> .separator :

sqlite> .import /etc/passwd pwtable

sqlite> select * from pwtable where user='root';

root:x:0:0:root:/root:/bin/bash

sqlite> select * from pwtable;

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

sqlite> .exit

Task #2

Your C program (a3p1task2.c) connect to the database and get all the entries in the pwtable (from Task#1) and output each record in a file ("a3p1task2.txt"). Each record should be formatted as shown below.

For the first record: root:x:0:0:root:/root:/bin/bash

apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

Task #3

Your program does an update to the sqlite3 database to do an update to a record where uid=48 for the gecos (comment) field to be updated as "My Apache Server for cs3376" as shown below.

update pwtable set gecos="My Apache Server for cs3377" where uid="48";

Your program does (interacting with sqlite3 database):

(1) get the record (of uid=48) and print the record with the headings shown in Task#2,

(2) update the record (of uid=48) so that the gecos will be "My Apache Server for cs3376", then

(3) get the updated record using select, and

(4) print the record to the console with a heading (as shown in Task #2).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions