Schl f Cmputer Science McGill University Schl f Cmputer Science COMP-206 Sftware Systems Due: September 29, 2008 n WEB CT at 23:55 Operating Systems This assignment explres the Unix perating system and hw its subsystems are interrelated. We will explre three areas f this system: the cmmand line subsystem, the batch file subsystem and the perating system shell. Questin 1: The Unix Operating System Cmmand Line In rder t help yu understand hw sftware systems wrk tgether, the gal f the curse is t build a rudimentary web stre. We will begin this here in questin ne. Many f the assignments will build n each ther, each with the gal f cmpleting a little bit mre f that web stre. As in all single user sftware prjects we must first reserve sme space n the hard drive t develp ur web stre applicatin. T d this, we will need t create a directry space. Using the Unix cmmand line build the fllwing directry structure: Within yur hme directry create a directry called PROJECTS. Within Prjects create the directry STORE. Within Stre create the directries: ARCHIVE, BACKUP, BUILD1, and DOCUMENTS. Within Build1 create the directries: SOURCE, DATA and RUNTIME. Within Surce create the directries: BATCH, C, HTML, CGI, PERL and PYTHON. As the curse prgresses we will create ur prgrams in the Batch, C, HTML, CGI, Pythn and PERL directries. Our database f prducts will be lcated in the DATA directry, and all the executables will be saved in the RUNTIME directry. This directry space is cnsidered t be a part f ur develpment envirnment. Later, we will have t put this n the web (fr real) and this will be dne in ur deplyment envirnment, PUBLIC_HTML (but that will cme later). The next thing we need t decide is the type f prducts we wuld like t sell. This I will leave up t yu, but we will need t create sme databases. Since this is nt a database curse and since many f yu have prbably nt prgrammed databases, ur database jvybihal Page 1 9/15/2008
Schl f Cmputer Science will be a "flat file" database (i.e. a text file). Yu MUST use VI t create tw f ur primary databases (there will be mre databases later): The first database is called INVENTORY.TXT. It will cntain the fllwing infrmatin: Prduct ID number, prduct name, quantity in stck, and unit price. Our secnd database is called MEMBERS.TXT. It will cntain the fllwing infrmatin: User ID, user passwrd, user name, security level (1 = supervisr, 0 = regular user), and purchase histry (dllar amunt sum). As the names imply the inventry database will recrd the prducts yur stre sells and hw many are in stck. The member database cntains the names f all the valid users f yur stre (like ebay). A flat file database is rganized arund recrds and fields. A field is each piece r type f infrmatin stred: like user ID r user passwrd. A recrd is a grup r set f fields. It cntains all the infrmatin abut a single user r prduct saved in yur database. In a flat file, the recrd is ne line and cmmas separate fields. Fr example, the member's database culd lk smething like this: 1234, abcd, Jseph Vybihal, 1, 500 9987, ddee, Bill Smith, 0, 20000 1072, ABCdef, Sam Smiley, 0, 100 Each rw cntains all the infrmatin abut ne user. This is called a recrd. A cmma separates each piece f infrmatin abut the user in that rw: ID first, then passwrd, fllwed by user name, etc. Pressing the carriage return terminates the recrd. There is als a carriage return n the last recrd. This leaves us with a blank line at the end f the file. This is kay. Fr questin 1 d: Create the develpment envirnment directry structure (recrd what yu did in a text file called STRUCT.TXT). I cannt cnfirm if yu actually created the directry structure using the cmmand-line. Yu culd have dne it using Windws and then pretended. T vercme this, I am asking yu t type ut the cmmands yu wuld use, in-rder in this text file, as if yu where at the cmmand-line actually ding it (Yu shuld ACTUALLY d it but the TA will nt verify this, nly the STRUCT.TXT file yu uplad t WEB CT). Using VI, create the tw databases INVENTORY.TXT and MEMBERS.TXT and ppulate them with data (build and save them in the directry DATA). Then send these text files t WEB CT. Again I cannt cnfirm if yu actually used VI but I suggest yu d, s that yu can be used t it fr exam questins. Questin 2: Operating Systems Shell Envirnments Every perating system has a shell. The shell is the part f the perating system that prcesses the cmmands frm the user and displays the user interface. This culd be a jvybihal Page 2 9/15/2008
Schl f Cmputer Science cmmand-line shell r a windwed shell. It is the envirnment in which yur prgram will run. It is als the envirnment in which yu will wrk in. Every shell has its advantages and disadvantages fr the sftware and the prgrammer. Lk carefully at the Unix and Windws perating systems (if yu have a MAC at hme d the cmparisn between Unix and the MAC). Identify the fllwing: List all the shells prvided by that perating system. Select tw shells and describe hw each shell accepts cmmands frm the user. hw each shell returns errrs t the user. Describe in shrt hw we can custmize and persnalize these shells, And state what is advantageus and what is disadvantageus in each shell. Nte: T answer this questin yu may have t d readings. Check the OS manual that cmes with yur cmputer, the Internet and the MAN cmmand in Unix r HELP in DOS. Uplad t Web CT a PDF r TXT file cntaining yu answer. Name this file SHELL.txt r SHELL.pdf. Questin 3: Lgin Shell Scripts Sme shells prvide a scripting envirnment. The scripting envirnment is a prgramming language fr the shell. These files are nt cmpiled. The shell interprets them. But they give the prgrammer an avenue where they can autmate perating system prcedures since all cmmand-line cmmands can be part f the script prgram. In additin they als prvide a rudimentary cntrl flw language that actually permits yu t d sme real prgramming (in the real sense f the science). Three frms f scripts exist in Unix: the set-up script, scripts prper and the batch script. Batch scripts are nly a special frm f the general purpse scripts prper. One f the mst cmmn frms f script prgramming in Unix is knwn as BASH. Set-up scripts are used t initialize r cleanup the shell envirnment when yu lgin. Shells are initiated and destryed when yu lgin and ut f the perating system. Yu are als permitted t switch shells at any time. Yu have the pprtunity t select the shell yu want t use and thrugh its setup script yu can custmize its lk and feel, and then clean up yur sessin when yu lgut (if yu need t). This assignment questin wants yu t custmize the Unix lgin set-up script. As discussed in class there are a few lgin script files in Unix depending n the shell yu are using. Identify the default shell that is in peratin during yur lgin and mdify its lgin script in the fllwing ways: jvybihal Page 3 9/15/2008
Schl f Cmputer Science Custmize the prmpt. Display the directry yu have been sent t Display the date and time List all the users currently lgged n Finger yur best friend Alias the ls -l -a cmmand t the wrd lsa, and Launch yur web brwser applicatin. Yur lgin script can prcess this in any rder yu like. Questin 4: Batch Prcessing Batch prcessing is a special use f scripts fr managing and autmating the executin f applicatins. Histrically they were created fr large mainframe cmputers that culd nly execute ne prgram at a time. Setting up a mainframe t execute a user's applicatin tk a lt f time. Therefre there was a lt f wasted time (and mney) between executins. Nrmally a "Jb" wuld run fr 0.5 secnds and the set-up time was 10 t 20 minutes. This was nt cst effective. The slutin was t have a special script that in the mrning wuld be built cntaining the instructins n hw t initialize the runtime envirnment, run the applicatin and perfrm any cleanup f files and allcated resurces fr each Jb. Then the mainframe wuld fly thrugh all these applicatins setting up the executin envirnment, printing the results and setting up fr the next Jb, until all were dne. BASH is the mdern batch prgramming envirnment. These days, we view a Jb as the tasks the user wants the cmputer t prcess autmatically. The user then waits fr the wrk t cmplete and verifies the results. Bash files are created as needed by the user, nt nce at the beginning f the day. Let us try a simple versin f this. Inside the BATCH directry create a bash file called VERIFY. Remember t use CHMOD t make it executable. VERIFY will be used t validate the MEMBERS.TXT flat file. It will perfrm the fllwing tasks; all the activity will be cntained within the single VERIFY.BAT file: Set-up prcedure fr Jb 1: Autmatically create a directry in STORE called TESTBED Cpy MEMBERS.TXT int TESTBED The applicatin t run fr Jb 1: Srt MEMBERS.TXT int SORTED.TXT (use the Unix cmmand) jvybihal Page 4 9/15/2008
Schl f Cmputer Science Cleanup prcedure fr Jb 1: Delete the MEMBERS.TXT file frm the TESTBED directry Set-up prcedure fr Jb 2: Autmatically create a text file called INVALID.TXT that is initialized with the wrds: PLEASE ENTER INVALID USERS, using the cmmands ECHO and redirectin The applicatin t run fr Jb 2: Open the file INVALID.TXT with VI. The user will enter names f users that are nt permitted t becme members f yur stre. The user will have t terminate VI manually befre the batch file cntinues executin. Cleanup prcedures fr Jb 2: Nthing Set-up prcedure fr Jb 3: Nthing The applicatin t run fr Jb 3: GREP SORTED.TXT with INVALID.TXT and save the results in FOUND.TXT Use MORE t display SORTED.TXT s that the user can visually verify if there are duplicate users Use MORE again t display FOUND.TXT t see if any unauthrized users have registered. Cpy FOUND.TXT and SORTED.TXT back int the directry DATA Cleanup Jb 3: Delete all the files in TESTBED and the directry TESTBED itself. WHAT TO HAND IN Everything must be submitted t WEB CT Vista befre the due date. Remember that WEB CT permits yu t hand in up t tw days late but there will be a penalty f 5% each day. After that, the WEB CT submissin bx will clse. There is a PROBLEM bx that yu can submit t n WEB CT. But I will nt be grading this bx. Yu must email me with a very very very gd reasn t why smething in the prblem bx shuld be graded. Please hand in the fllwing: jvybihal Page 5 9/15/2008
Schl f Cmputer Science Fr questin 1: STRUCT.TXT, INVENTORY.TXT and MEMBERS.TXT. Please remember that STRUCT.TXT cntains the cmmand-line sessin yu used t create the requested directry structure. Include ALL the Unix cmmands yu used, in rder. Fr questin 2: SHELL.TXT r SHELL.PDF that will cntain yur essay abut Unix and Windws shell cmparisns (ptinally Unix/Mac). The lgin script that yu are using. Fr questin 3: The lgin file yu edited. Fr questin 4: VERIFY, SORTED.TXT and FOUND.TXT HOW IT WILL BE GRADED The TA will use the fllwing instructins when grading yur assignment. TA's are ften given additinal instructins nt presented here but cmpiled frm cmmn student questins r fund prblems in the assignment r adjustments t the assignment / prcedures. ASSIGNMENT: is wrth a ttal f 20 pints. QUESTION 1: is wrth 5 pints. +3 STRUCT.TXT, prprtinal t the number f crrect cmmands presented +2 Prper structure f bth flat files QUESTION 2: is wrth 5 pints. +3 Prprtinal grading based n the prper identificatin f shells and features in SHELL.TXT +2 Prprtinal grading based n the crrect cmmands used in the lgin script QUESTION 3: is wrth 5 pints. Graded prprtinally. QUESTION 4: is wrth 5 pints. +3 Prprtinal grading based n the crrect cmmands and setup f the batch file +2 the existence and crrect frmat f the SORTED.TXT and FOUND.TXT files. Maker sure that FOUND.TXT actually fund smene. jvybihal Page 6 9/15/2008