Friday, January 18, 2013

Sad (System Analysis & Design) Assignment

1.     Discuss analytical representation of a system.

As an abstraction we symbolically represent a system as a simple entity by using a rectangular box as shown in Figure 1. In general, inputs such as stimuli and cues are fed into a system that processes the inputs and produces an output. As a construct, this symbolism is acceptable; however, the words need to more explicitly identify WHAT the system performs. That is, the system must add value to the input in producing an output.

We refer to the transformational processing that adds value to inputs and produces an output as a capability. You will often hear people refer to this as the system’s functionality; this is partially correct. Functionality only represents the ACTION to be accomplished; not HOW WELL as characterized by performance. This text employs capability as the operative term that encompasses both the functionality and performance attributes of a system.

The simple diagram presented in Figure 1 represents a system. However, from an analytical perspective, the diagram is missing critical information that relates to how the system operates and performs within its operating environment. Therefore, we expand the diagram to identify these missing elements. The result is shown in Figure 2. The attributes of the construct—which include desirable/undesirable inputs, stakeholders, and desirable/undesirable outputs—serve as a key checklist to ensure that all contributory factors are duly considered when specifying, designing, and developing a system.


Figure 1 - Basic System Entity Construct

2.     Explain in brief the four primary system development models.

Ans- The Waterfall Model The Waterfall Model is the earliest method of structured system development.  Although it has come under attack in recent years for being too rigid and unrealistic when it comes to quickly meeting customer’s needs, the Waterfall Model is still widely used.  It is attributed with providing the theoretical basis for other Process Models, because it most closely resembles a “generic” model for software development.

The Waterfall Model consists of the following steps:

· System Conceptualization.  System Conceptualization refers to the consideration of all aspects of the targeted business function or process, with the goals of determining how each of those aspects relates with one another, and which aspects will be incorporated into the system.

· Systems Analysis.  This step refers to the gathering of system requirements, with the goal of determining how these requirements will be accommodated in the system.  Extensive communication between the customer and the developer is essential.

· System Design.  Once the requirements have been collected and analyzed, it is necessary to identify in detail how the system will be constructed to perform necessary tasks.  More specifically, the System Design phase is focused on the data requirements , the software construction , and the interface construction .

· Coding.  Also known as programming, this step involves the creation of the system software.  Requirements and systems specifications from the System Design step are translated into machine readable computer code.

· Testing.  As the software is created and added to the developing system, testing is performed to ensure that it is working correctly and efficiently.   The goal of external effectiveness testing is to verify that the software is functioning according to system design, and that it is performing all necessary functions or sub-functions.  The goal of internal testing is to make sure that the computer code is efficient, standardized, and well documented.  Testing can be a labor-intensive process, due to its iterative nature. Problems/Challenges associated with the Waterfall Model Although the Waterfall Model has been used extensively over the years in the production of many quality systems, it is not without its problems.  In recent years it has come under attack, due to its rigid design and inflexible procedure.  Criticisms fall into the following categories:

· Developing a system using the Waterfall Model can be a long, painstaking process that does not yield a working version of the system until late in the process.

Iterative Development

The problems with the Waterfall Model created a demand for a new method of developing systems which could provide faster results, require less up-front information, and offer greater flexibility.  With Iterative Development, the project is divided into small parts.  This allows the development team to demonstrate results earlier on in the process and obtain valuable feedback from system users.  Often, each iteration is actually a mini-Waterfall process with the feedback from one phase providing vital information for the design of the next phase.  In a variation of this model, the software products which are produced at the end of each step (or series of steps) can go into production immediately as incremental releases.

Problems/Challenges associated with the Iterative Model

While the Iterative Model addresses many of the problems associated with the Waterfall Model, it does present new challenges.

· The user community needs to be actively involved throughout the project.  While this involvement is a positive for the project, it is demanding on the time of the staff and can add project delay.

  • Communication and coordination skills take center stage in project development.
  • Informal requests for improvement after each phase may lead to confusion -- a controlled mechanism for handling substantive requests needs to be developed.
  • The Iterative Model can lead to “scope creep,” since user feedback following each phase may lead to increased customer demands.  As users see the system develop, they may realize the potential of other system capabilities which would enhance their work.

Prototyping

The Prototyping Model was developed on the assumption that it is often difficult to know all of your requirements at the beginning of a project.  Typically, users know many of the objectives that they wish to address with a system, but they do not know all the nuances of the data, nor do

they know the details of the system features and capabilities.  The Prototyping Model allows for these conditions, and offers a development approach that yields results without first requiring all information up-front .

When using the Prototyping Model, the developer builds a simplified version of the proposed system and presents it to the customer for consideration as part of the development process.  The customer in turn provides feedback to the developer, who goes back to refine the system

requirements to incorporate the additional information.  Often, the prototype code is thrown away and entirely new programs are developed once requirements are identified.

There are a few different approaches that may be followed when using the Prototyping Model:

· creation of the major user interfaces without any substantive coding in the background in order to give the users a “feel” for what the system will look like, development of an abbreviated version of the system that performs a limited subset of functions; development of a paper system . use of an existing system or system components to demonstrate some functions that will be included in the developed system.

Prototyping is comprised of the following steps:

  • Requirements Definition/Collection.
    Similar to the Conceptualization phase of the Waterfall Model, but not as comprehensive.  The information collected is usually limited to a subset of the complete system requirements.
  • Design.
    Once the initial layer of requirements information is collected, or new information is gathered, it is rapidly integrated into a new or existing design so that it may be folded into the prototype.
  • Prototype Creation/Modification.  The information from the design is rapidly rolled into a prototype. This may mean the creation/modification of paper information, new coding, or modifications to existing coding.
  • Assessment.   The prototype is presented to the customer for review.  Comments and suggestions are collected from the customer.
  • Prototype Refinement.  Information collected from the customer is digested and the prototype is refined.  The developer revises the prototype to make it more effective and efficient.
  • System Implementation.  In most cases, the system is rewritten once requirements are understood.  Sometimes, the Iterative process eventually produces a working system that can be the cornerstone for the fully functional system.

Problems/Challenges associated with the Prototyping Model

Criticisms of the Prototyping Model generally fall into the following categories:

  • · Prototyping can lead to false expectations.  Prototyping often creates a situation where the customer mistakenly believes that the system is “finished” when in fact it is not. More specifically, when using the Prototyping Model, the pre-implementation versions of a system are really nothing more than one-dimensional structures.  The necessary, behind the-scenes work such as database normalization, documentation, testing, and reviews for efficiency have not been done.  Thus the necessary underpinnings for the system are not in place.
  • · Prototyping can lead to poorly designed systems.  Because the primary goal of Prototyping is rapid development, the design of the system can sometimes suffer because the system is built in a series of “layers” without a global consideration of the integration of all other components.  While initial software development is often built to be a “throwaway,” attempting to retroactively produce a solid system design can sometimes be problematic.

The Spiral Model

The Spiral Model was designed to include the best features from the Waterfall and Prototyping Models, and introduces a new component - risk-assessment.  The term “spiral” is used to describe the process that is followed as the development of the system takes place.  Similar to the Prototyping Model, an initial version of the system is developed, and then repetitively modified based on input received from customer evaluations.  Unlike the Prototyping Model, however, the development of each version of the system is carefully designed using the steps involved in the Waterfall Model.  With each iteration around the spiral, progressively more complete versions of the system are built.
Risk assessment is included as a step in the development process as a means of evaluating each version of the system to determine whether or not development should continue. If the customer decides that any identified risks are too great, the project may be halted.  For example, if a substantial increase in cost or project completion time is identified during one phase of risk assessment, the customer or the developer may decide that it does not make sense to continue with the project, since the increased cost or lengthened timeframe may make continuation of the project impractical or unfeasible.
The Spiral Model is made up of the following steps:

  • · Project Objectives.  Similar to the system conception phase of the Waterfall Model. Objectives are determined, possible obstacles are identified and alternative approaches are weighed.
  • · Risk Assessment.  Possible alternatives are examined by the developer, and associated risks/problems are identified.  Resolutions of the risks are evaluated and weighed in the consideration of project continuation.  Sometimes prototyping is used to clarify needs.

  •  Engineering & Production.  Detailed requirements are determined and the software piece is developed.

  •  Planning and Management.  The customer is given an opportunity to analyze the results of the version created in the Engineering step and to offer feedback to the developer.

3.     Give the overview of system life cycle.

Ans- The systems development life cycle (SDLC) is a conceptual model used in project management that describes the stages involved in an information system development project, from an initial feasibility study through maintenance of the completed application.

Various SDLC methodologies have been developed to guide the processes involved, including the waterfall model (which was the original SDLC method); rapid application development (RAD); joint application development (JAD); the fountain model; the spiral model; build and fix; and synchronize-and-stabilize. Frequently, several models are combined into some sort of hybrid methodology. Documentation is crucial regardless of the type of model chosen or devised for any application, and is usually done in parallel with the development process. Some methods work better for specific types of projects, but in the final analysis, the most important factor for the success of a project may be how closely the particular plan was followed.

In general, an SDLC methodology follows the following steps:

  1. The existing system is evaluated. Deficiencies are identified. This can be done by interviewing users of the system and consulting with support personnel.
  2. The new system requirements are defined. In particular, the deficiencies in the existing system must be addressed with specific proposals for improvement.
  3. The proposed system is designed. Plans are laid out concerning the physical construction, hardware, operating systems, programming, communications, and security issues.
  4. The new system is developed. The new components and programs must be obtained and installed. Users of the system must be trained in its use, and all aspects of performance must be tested. If necessary, adjustments must be made at this stage.
  5. The system is put into use. This can be done in various ways. The new system can phased in, according to application or location, and the old system gradually replaced. In some cases, it may be more cost-effective to shut down the old system and implement the new system all at once.
  6. Once the new system is up and running for a while, it should be exhaustively evaluated. Maintenance must be kept up rigorously at all times. Users of the system should be kept up-to-date concerning the latest modifications and procedures

The Waterfall Model

This is the classic SDLC model, with a linear and sequential method that has goals for each development phase. The waterfall model simplifies task scheduling, because there are no iterative or overlapping steps. One drawback of the waterfall is that it does not allow for much revision.

  1. Rapid Application Development (RAD)
    This model is based on the concept that better products can be developed more quickly by: using workshops or focus groups to gather system requirements; prototyping and reiterative testing of designs; rigid adherence to schedule; and less formality of team communications such as reviews.
  2. Joint Application Development (JAD)
    This model involves the client or end user in the design and development of an application, through a series of collaborative workshops called JAD sessions. 
  3. The Prototyping Model
    DESIGN AND DEVELOPMENT
  4. In this model, a prototype (an early approximation of a final system or product) is built, tested, and then reworked as necessary until an acceptable prototype is finally achieved from which the complete system or product can now be developed.
  5. Synchronize-and-Stabilize
    This model involves teams working in parallel on individual application modules, frequently synchronizing their code with that of other teams and stabilizing code frequently throughout the development process.
  6. The Spiral Model
    This model of development combines the features of the prototyping model and the waterfall model. The spiral model is favored for large, expensive, and complicated projects.

5.Explain feasibility study and its types.

Ans4- A feasibility study   is performed by a company when they want to know whether a project is possible given certain circumstances. Feasibility studies are undertaken under many circumstances - to find out whether a company has enough money for a project, to find out whether the product being created will sell, or to see if there are enough human resources for the project. A good feasibility study will show the strengths and deficits before the project is planned or budgeted for. By doing the research beforehand, companies can save money and resources in the long run by avoiding projects that are not feasible.

What are the Types of Feasibility Studies?
There are many different types of feasibility studies; here is a list of some of the most common:

  • ·         Technical Feasibility - does the company have the technological resources to undertake the project? Are the processes and procedures conducive to project success?
  • ·         Schedule Feasibility - does the company currently have the time resources to undertake the project? Is the project completable in the available time?
  • ·         Economic Feasibility - given the financial resources of the company, is the project something that can be completed? The economic feasibility study is more commonly called the cost/benefit analysis.
  • ·         Cultural Feasibility - what will the impact on both local and general cultures be? What sort of environmental implications does the feasibility study have?
  • ·         Legal/Ethical Feasibility - what are the legal implications of the project? What sort of ethical considerations are there? You need to make sure that any project undertaken will meet all legal and ethical requirements before the project is on the table.
  • ·         Resource Feasibility - do you have enough resources, what resources will be required, what facilities will be required for the project, etc.
  • ·         Operational Feasibility - this measures how well your company will be able to solve problems and take advantage of opportunities that are presented during the course of the project
  • ·         Marketing Feasibility - will anyone want the product once its done? What is the target demographic? Should there be a test run? Is there enough buzz that can be created for the product?
  • ·         Real Estate Feasibility - what kind of land or property will be required to undertake the project? What is the market like? What are the zoning laws? How will the business impact the area?
  • ·         Comprehensive Feasibility - this takes a look at the various aspects involved in the project - marketing, real estate, cultural, economic, etc. When undertaking a new business venture, this is the most common type of feasibility study performed.
 Ans 1: (a) System Testing

Testing the behavior of the whole software/system as defined in software requirements specification(SRS) is known as system testing, its main focus is to verify that the customer requirements are fulfilled.

System testing is done after integration testing is complete. System testing should test functional and non functional requirements of the software.

Following types of testing should be considered during system testing cycle. The test types followed in system testing differ from organization to organization however this list covers some of the main testing types which need to be covered in system testing.

  • Sanity Testing
  • Usability Testing
  • Stress Testing
  • Load Testing
  • Performance Testing
  • Regression Testing
  • Maintenance Testing
  • Security Testing
  • Accessibility Testing

(b) Integration Testing

Integration Testing is a level of the software testing process where individual units are combined and tested as a group.
The purpose of this level of testing is to expose faults in the interaction between integrated units.

Test drivers and test stubs are used to assist in Integration Testing.

Note: The definition of a unit is debatable and it could mean any of the following:

1.       the smallest testable part of a software

2.       a ‘module’ which could consist of many of  ’1′

3.       a ‘component’ which could consist of many of ’2′

ANALOGY

During the process of manufacturing a ballpoint pen, the cap, the body, the tail and clip, the ink cartridge and the ballpoint are produced separately and unit tested separately. When two or more units are ready, they are assembled and Integration Testing is performed. For example, whether the cap fits into the body or not.

METHOD

Any of Black Box Testing, White Box Testing, and Gray Box Testing methods can be used. Normally, the method depends on your definition of ‘unit’.

Ans 2: Explain the following Software design concepts:

(a)    Abstraction : 
  concentrate on the essential features and ignore details that are not relevant
  • ·         Procedural abstraction = a named sequence of instructions that has a specific & limited function
  • ·         Data abstraction = a named collection of data that describes a data object
  • ·         Control abstraction = implies a program control mechanisms without specify internal details

(b)   Refinement:

  • ·         stepwise refinement = top down strategy
  • ·         refine levels of procedural detail
  • ·         develop hierarchy by decompose a procedural

abstraction in a stepwise fashion until programming

languages are reached

·         similar to the process of refinement & partitioning in

requirement analysis

·         abstraction & refinement are complementary

concepts

Eg-1)  Suppress lowlevel details

      2) Reveal low-leveldetails

(c)    Modularity:

·         system is decomposed into a number of modules

·         software architecture and design patterns embody modularity

·         5 criteria to evaluate a design method with respect to its ability to

define effective modular system

    i.   modular decomposability

provides a systematic approach for decomposing the problem into subproblems

    ii.  modular composability

- enables existing(reusable) design components to be assembled into a new system

    iii. modular understandability

- module can be understood as a standalone unit (no need to refer to other modules)

    iv. modular continuity

- small changes to the system requirements result in changes to individual modules

    v.  modular protection

- unexpected condition occurs within a module & its effects are constrained within that module

(d)   Control Hierarchy:

·  also called program structure

·  represent the organization of program components

·  depth & width = no. of levels of control & overall span of control

·   fan-out = no. of. Modules that are directly controlled by another module

·   fan-in = how many modules directly control a given module

·   super ordinate = module that control another module

·   subordinate = module controlled by another

Ans 3:  Software Quality Assurance Activities

SQA is the process of evaluating the quality of a product and enforcing adherence
to software product standards and procedures. It is an umbrella activity that ensures conformance to standards and procedures throughout the SDLC of a software product. There are a large number of tasks involved in SQA activities.

These include:

i. Formulating a quality management plan

ii. Applying software engineering techniques

iii. Conducting formal technical reviews

iv. Applying a multi-tiered testing strategy

v. Enforcing process adherence

vi. Controlling change

vii. Measuring impact of change

viii. Performing SQA audits

ix. Keeping records and reporting


i. Formulating a Quality Management Plan

One of the tasks of SQA is the formulation of a quality management plan. The quality management plan identifies the quality aspects of the software product to be developed. It helps in planning checkpoints for work products and the development process. It also tracks changes made to the development process based on the results of the checks. The quality management plan is tracked as a

live plan throughout the SDLC.

ii. Applying Software Engineering

Application of software engineering techniques helps the software designer to achieve high quality specification. The designer gathers information using techniques such as interviews and FAST. Using the information gathered, the designer prepares project estimation with the help of techniques such as WBS,SLOC estimation, or FP estimation.
iii. Conducting Formal Technical Reviews

Formal technical review (FTR) in conducted to assess the quality and design of the prototype. It is a meeting with the technical staff to discuss the quality requirements of a software product and its design quality. FTRs help in detecting errors at an early phase of development. This prevents errors from percolating down to the latter phases and resulting in rework.

iv. Applying a Multi-tiered Testing Strategy

Software testing is a critical task of SQA activity, which aims at error detection.
Unit testing is the first level of testing. The subsequence levels of testing areintegration testing and system level testing. There are various testing strategies followed by organization. At times, developers perform unit testing and integration testing with independence testing support. There are also occasions where testers perform functional testing and system level testing with developer

support. Sometimes beta testing with selected clients is also conducted to test the product before it is finally released.

v. Enforcing Process Adherence
This task of SQA emphasizes the need for process adherence during product development. In addition, the development process should also adhere toprocedures defined for product development. Therefore, this is a combination of two tasks, product evaluation and process monitoring.

vi. Product Evaluation

Product evaluation ensures that the standards laid down for a project are followed.During product evaluation, the compliance of the software product to the existing standards is verified. Initially, SQA activities are conducted to monitor the standards and procedures of the project. Product evaluation ensures that the software product reflects the requirements identified in the project management plan.

vii. Process Monitoring
Process monitoring ensures that appropriate steps to follow the product development procedures are carried out. SQA monitors processes by comparing the actual steps carried out with the steps in the documented procedures.
Product evaluation and process monitoring ensure that the development and control processes described in the project management plan are correctly carried out. These tasks ensure that the project-re1ated procedures and standards are followed. They also ensure that products and processes conform to standards and procedures. Audits ensure that product evaluation and process monitoring are performed.

viii. Controlling Change
This task combines human procedures and automated tools to provide a mechanism for change control. The change control mechanism ensures software quality by formalizing requests for change, evaluating the nature of change, and controlling the impact of change. Change control mechanism is implemented during the development and maintenance stages.

ix. Measuring Impact of Change
Change is inevitable in the SDLC. However, the change needs to be measured and monitored. Changes in the product or process are measured using software qualitymetrics. Software qua1ity metrics helps in estimating the cost and resource requirements of a project. To control software quality; it is essential to measurequality and then compare it with established standards. Software qua1ity metrics are used to evaluate the effectiveness of techniques and tools, the productivity of development activities and the qua1ity of products. Metrics enables mangers and developers to monitor the activities and proposed changes throughout the SDLC and initiate corrective actions and  analysis.

x. Performing SQA Audits
SQA audits scrutinize the software development process by comparing it to
established processes. This ensures that proper control is maintained over the
documents required during SDLC. Audits also ensure that the status of an activity
performed by the developer is reflected in the status report of the developer.

xi. Keeping Records and Reporting
Keeping records and reporting ensure the collection and circulation of information
relevant to SQA. The results of reviews, audits, change control, testing, and other
SQA activities are reported and compiled for future reference.

DBMS Assignment Important Ques and answer



    1.    A well-maintained relational DBMS has a high level of data integrity. What features of a relational DBMS contribute towards this level of integrity?

Ans- Features of DBMS

The following are main features offered by DBMS.

Apart from these features different database management systems may offer different features.

For instance, Oracle is increasing being fine-tuned to be the database for Internet applications.  This may not be found in other database management systems.  These are the general features of database management systems. Each DBMS has its own way of implementing it. A DBMS may have more features the features discussed here and may also enhance these features.

Support for large amount of data Each DBMS is designed to support large amount of data. They provide special ways and means to store and manipulate large amount of data.  Companies are trying to store more and more amount of data. Some of this data will have to be online (available every time).

In most of the cases the amount of data that can be stored is not actually constrained by DBSM and instead constrained by the availability of the hardware.

For example,

Oracle can store terabytes of data. Data sharing, concurrency and locking

DBSM also allows data to be shared by two or more users.  The same data can be accessed by multiple users at the same time – data concurrency. However when same data is being manipulated at the same time by multiple users  certain problems arise. To avoid these problems, DBMS locks data that is being manipulated to avoid two users from modifying the same data at the same time. The locking mechanism is transparent and automatic. Neither we have to inform to DBMS about locking nor we need to know how and when DBMS is locking the data. However, as a programmer, if we can know intricacies of locking mechanism used by DBMS, we will be better programmers. Data Security While DBMS allowing data to be shared, it also ensures that data in only accessed by authorized users. DBMS provides features needed to implement security at the enterprise level. By default, the data of a user cannot be accessed by other users unless the owner gives explicit permissions to other users to do so.                                                           

Data Integrity

Maintaining integrity of the data is an import process. If data loses integrity, it becomes unusable and garbage. DBMS provides means to implement rules to maintain integrity of the data. Once we specify which rules are to be implemented, then DBMS can make sure that these rules are implemented always.

Fault tolerance and recovery

DBMS provides great deal of fault tolerance. They continue to run in spite of errors, if possible, allowing users to rectify the mistake in the mean time. DBSM also allows recovery in the event of failure. For instance, if data on the disk is completely lost due to disk failure then also data can be recovered to the point of failure if proper back up of the data is available.

Entity and Attribute

An entity is any object that is stored in the database.  Each entity is associated with a collection of attributes. For example, if you take a data of a training institute, student is an entity as we store information about each student in the database. Each student is associated with certain values such as roll number, name, course etc., which are

called as attributes of the entity. There will be relationship among entities. The relationship between entities may be one-to-one, one-to-many or many-to-many. If you take entities student, batch and subject, the following are the possible

relationships.

There is one-to-one relationship between batch and subject.  One batch is associated with only one subject. Three is one-to-many relationship between batch and student entities. One batch may contain many students. There is many-to-many relationship between student and subject entities. A single student may take many subjects and a single subject may be taken by multiple students.

Data Models

Data model is a way of storing and retrieving the data.  There are three different data models. Data models differ in the way they allow users to view and manipulate relationships between entities. Each has its own way of storing the data. The following are the three different data models:

 Hierarchical

 Network

 Relational

Hierarchical

In this model, data is stored in the form of a tree.  The data is represented by parent child relationship.  Each tree contains a single root record and one or more subordinate records. For example, each batch is root and students of the batch will be subordinates.

This model supports only one-to-many relationship between entities.

This was used in IBM’s Information management system, IMS.                                       

Network

Data is stored along with pointers, which specify the relationship between entities.

This was used in Honeywell's Integrated Data Store, IDS.

This model is complex. It is difficult to understand both the way data is stored and the way data is manipulated.  It is capable of supporting many-to-many relationship between entities, which hierarchical model doesn’t.

Relational

This stores data in the form of a table. Table is a collection of rows and columns.  

   2.    Explain the various functions of RDBMS? Name the different categories of RDBMS users and how they are different from each other.

Ans- There are several functions that a DBMS performs to ensure data integrity and consistency of data in the database. The ten functions in the DBMS are: data dictionary management, data storage management, data transformation and presentation, security management, multiuser access control, backup and recovery management, data integrity management, database access languages and application programming interfaces, database communication interfaces, and transaction management.

1.Data Dictionary Management:

Data Dictionary is where the DBMS stores definitions of the data elements and their relationships (metadata).  The DBMS uses this function to look up the required data component structures and relationships. When programs access data in a database they are basically going through the DBMS. This function removes structural and data dependency and provides the user with data abstraction. In turn, this makes things a lot easier on the end user. The Data Dictionary is often hidden from the user and is used by Database Administrators and Programmers.
2.Data Storage Management:

                This particular function is used for the storage of data and any related data entry forms or screen definitions, report definitions, data validation rules, procedural code, and structures that can handle video and picture formats. Users do not need to know how data is stored or manipulated. Also involved with this structure is a term called performance tuning that relates to a database’s efficiency in relation to storage and access speed.

3.Data Transformation and Presentation:
This function exists to transform any data entered into required data structures. By using the data transformation and presentation function the DBMS can determine the difference between logical and physical data formats.

4.       Security Management:

 This is one of the most important functions in the DBMS. Security management sets rules that determine specific users that are allowed to access the database. Users are given a username and password or sometimes through biometric authentication (such as a fingerprint or retina scan) but these types of authentication tend to be more costly. This function also sets restraints on what specific data any user can see or manage.

5.Multiuser Access Control:

   Data integrity and data consistency are the basis of this function. Multiuser access control is a very useful tool in a DBMS, it enables multiple users to access the database simultaneously without affecting the integrity of the database.

6.Backup and Recovery Management:

Backup and recovery is brought to mind whenever there is potential outside threats to a database. For example if there is a power outage, recovery management is how long it takes to recover the database after the outage. Backup management refers to the data safety and integrity; for example backing up all your mp3 files on a disk.

7.Data Integrity Management:

 The DBMS enforces these rules to reduce things such as data redundancy, which is when data is stored in more than one place unnecessarily, and maximizing data consistency, making sure database is returning correct/same answer each time for same question asked.

8.Database Access Languages and Application Programming Interfaces:

  A query language is a nonprocedural language. An example of this is SQL (structured query language). SQL is the most common query language supported by the majority of DBMS vendors. The use of this language makes it easy for user to specify what they want done without the headache of explaining how to specifically do it.

9.Database Communication Interfaces:  

 This refers to how a DBMS can accept different end user requests through different network environments. An example of this can be easily related to the internet.  A DBMS can provide access to the database using the Internet through Web Browsers (Mozilla Firefox, Internet Explorer, Netscape).
10.Transaction Management: 

 This refers to how a DBMS must supply a method that will guarantee that all the updates in a given transaction are made or not made.All transactions must follow what is called the ACID properties.

A – Atomicity: states a transaction is an indivisible unit that is either performed as a whole and not by its parts, or not performed at all.It is the responsibility of recovery management to make sure this takes place.

C – Consistency:A transaction must alter the database from one constant state to another constant state. I – Isolation:Transactions must be executed independently of one another.Part of a transaction in progress should not be able to be seen by another transaction. D – Durability:A successfully completed transaction is recorded permanently in the database and must not be lost due to failures.

 Alternate key - An alternate key is any candidate key which is not selected to be the primary key
* Candidate key - A candidate key is a field or combination of fields that can act as a primary key field for that table to uniquely identify each record in that table.
For Eg:
The table:
Emloyee(Name,Address,Ssn,Employee_Idprimary_key,Phone_ext)
In the above example Ssn no. and employee identity are ccandidate keys.

* Compound key - compound key (also called a composite key or concatenated key) is a key that consists of 2 or more attributes.
* Primary key - a primary key is a value that can be used to identify a unique row in a table. Attributes are associated with it. Examples of primary keys are Social Security numbers (associated to a specific person) or ISBNs (associated to a specific book).
In the relational model of data, a primary key is a candidate key chosen as the main method of uniquely identifying a tuple in a relation.
For Eg:
Emloyee(Name,Address,Ssn,Employee_Idprimary_key,Phone_ext)

* Superkey - A superkey is defined in the relational model as a set of attributes of a relation variable (relvar) for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set. Equivalently a superkey can also be defined as a set of attributes of a relvar upon which all attributes of the relvar are functionally dependent.
For Eg:
Emloyee(Name,Address,Ssn,Employee_Idprimary_key,Phone_ext)



All the above are super keys.

* Foreign key - a foreign key (FK) is a field or group of fields in a database record that points to a key field or group of fields forming a key of another database record in some (usually different) table. Usually a foreign key in one table refers to the primary key (PK) of another table. This way references can be made to link information together and it is an essential part of database normalization.
For Eg:
For a Student....
School(Name,Address,Phone,School_Reg_noprimary_key

   (b) RDBMS has become most popular Database System world wide? Justify your answer with suitable example.

 3.   Explain different integrity constrains supported by RDBMS and ORDBMS with suitable examples

 Ans- Integrity Constraints are the set of constructs provided by a data model for specifying conditions that must be satisfied by the data. An Integrity constraint (IC) is a condition specified on a database schema and restricts the data that can be stored in an instance of the database.

Integrity constraints can be-

i.  Domain Constraints

ii. Key Constraints

iii.Foreign Key Constraints

iv. General Constraints

Domain Constraints

-  Domain refers to a set of possible values for each attribute associated with an entity set.

-  Domain constraints in the schema specify an important condition that the user wants each instance of the relation to satisfy.


 Key Constraints

- A Key Constraint is a statement that a certain minimal subset of the fields of a relation is a unique identifier for a tuple.

- Super Key :  It is a set of one or more attributes which put together enable us to identify uniquely an entity in the entity set.
- Candidate Key : A set of fields that uniquely identifies a tuple according to a key constraint is called a candidate key.  A superkey for which no subset is a superkey is called a candidate key.  ( A superkey that is minimal is a candidate key ) Eg.  In students relation, sid is candidate key.

- Primary Key : It is a candidate key (there may be more than one) chosen by the database designer to identify entities in an entity set.

Foreign Key Constraints

- The most common IC involving two relations is a foreign key constraint.

- Foreign Key : If the primary key of one table is referenced in the other table, then that key is called as foreign key in the another table.  The foreign key in the referencing relation must match the primary key of the referenced relation.

General Constraints

- General constraints : Domain, primary key and foreign key constraints are considered to be a fundamental part of the relational data model.  It is also necessary to specify more general constraints.
- General constraints are- Table Constraints – Table constraints are associated with a single table and checked whenever the table is modified.
- Assertions – Assertions involve several tables and are checked whenever any of these tables is modified.


DBMS stands for Database Management System which is a general term for a set of software dedicated to controlling the storage of data.
RDMBS stand for Relational DataBase Management System.

DBMS includes the theritical part that how datas are stored in a table.It does not relates tables with another. While RDBMS is the procedural way that includes SQL syntaxes for relating tables with another and handling datas stored in tables. 

In DBMS all the tables are treated as different entities. There is no relation established among these entities.

ORDBMS = ODBMS + RDBMS = (O + R) * DB * MS. On a logical level, an ORDBMS is the MS process methods applied for DB data structure, which is complied with O object and R relational concepts. 


 4. Write SQL statements to create a table from existing table. What are the advantages of creating a table from existing table?

CREATE TABLE dbo.Tmp_Names
    (
      Id int NOT NULL
             IDENTITY(1, 1),
      Name varchar(50) NULL
    )
ON  [PRIMARY]
go

SET IDENTITY_INSERT dbo.Tmp_Names ON
go

IF EXISTS ( SELECT  *
            FROM    dbo.Names )
    INSERT  INTO dbo.Tmp_Names ( Id, Name )
            SELECT  Id,
                    Name
            FROM    dbo.Names TABLOCKX
go

SET IDENTITY_INSERT dbo.Tmp_Names OFF
go

DROP TABLE dbo.Names
go

Exec sp_rename 'Tmp_Names', 'Names'

I need to change the primary key of a table to an identity column, and there's already a number of rows in table.

I've got a script to clean up the IDs to ensure they're sequential starting at 1, works fine on my test database.

 5. What do you mean by ‘view’? What are its different types? Differentiate between updatable and non updatable ‘view’ with suitable examples. Also give proper syntax for creating ‘view’.

Ans- A View is a "Virtual Table". It is not like a simple table, but is a virtual table which contains columns and data from different tables (may be one or more tables). A View does not contain any data, it is a set of queries that are applied to one or more tables that is stored within the database as an object. After creating a view from some table(s), it used as a reference of those tables and when executed, it shows only those data which are already mentioned in the query during the creation of the View.
Different types of Views

There are two different types of Views:

    System Views
        Information Schema View
        Catalog View
        Dynamic Management View (DMV)
    User Defined Views
        Simple View
        Complex View

Now we will take a look at the different types of Views in SQL Server 2005.
System Views

In SQL Server, there are a few system databases like Master, Temp, msdb, and tempdb. Each and every database has its own responsibility, like Master data is one of the template databases for all the databases which are created in SQL Server 2005. Similarly, System Views are predefined Microsoft created Views that already exist in the Master database. These are also used as template Views for all new databases. These system Views will be automatically inserted into any user created database. There are around 230 system Views available.
Information View

These are one of the most important system grouped Views. There are twenty different schema Views in this group. These are used for displaying most physical information of a database, such as table and columns. The naming convention of this type of Views is INFORMATION_SCHEMA.[View Name]. From the system View image, we can get the names of a few Information Schema Views.
Catalog View

These types of Views were introduced in SQL Server 2005. Catalog Views are categorized in to different groups also. These are used to show database self describing information.

For example:

select * from sys.tables

The following notes apply to updatable views:

An updatable view is one you can use to insert, update, or delete base table rows. You can create a view to be inherently updatable, or you can create an INSTEAD OF trigger on any view to make it updatable.

To learn whether and in what ways the columns of an inherently updatable view can be modified, query the USER_UPDATABLE_COLUMNS data dictionary view. The information displayed by this view is meaningful only for inherently updatable views. For a view to be inherently updatable, the following conditions must be met:

    Each column in the view must map to a column of a single table. For example, if a view column maps to the output of a TABLE clause (an unnested collection), then the view is not inherently updatable.

    The view must not contain any of the following constructs:

A set operator

A DISTINCT operator

An aggregate or analytic function

A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause

A collection expression in a SELECT list

A subquery in a SELECT list

A subquery designated WITH READ ONLY

Joins, with some exceptions,

CREATE VIEW emp_view AS

   SELECT last_name, salary*12 annual_salary

   FROM employees

   WHERE department_id = 20;

    Explain the difference between the Drop & Delete, Commit & Rollback and Alter & Update with suitable examples.

Ans- The DELETE Statement is used to delete rows from a table.

The Syntax of a SQL DELETE statement is:

DELETE FROM table_name [WHERE condition];

·         table_name -- the table name which has to be updated.

NOTE:The WHERE clause in the sql delete command is optional and it identifies the rows in the column that gets deleted. If you do not include the WHERE clause all the rows in the table is deleted, so be careful while writing a DELETE query without WHERE clause.

For Example: To delete an employee with id 100 from the employee table, the sql delete query would be like,

DELETE FROM employee WHERE id = 100;

To delete all the rows from the employee table, the query would be like,

DELETE FROM employee;

The SQL DROP command is used to remove an object from the database. If you drop a table, all the rows in the table is deleted and the table structure is removed from the database. Once a table is dropped we cannot get it back, so be careful while using RENAME command. When a table is dropped all the references to the table will not be valid.

Syntax to drop a sql table structure:

DROP TABLE table_name;

For Example: To drop the table employee, the query would be like

DROP TABLE employee;

COMMIT command makes the transaction permanent.

ROLLBACK command undo the transaction.

in sql commit is used for saving the changes made in database and roll back is to roll back them , changes will not get saved in the database

Update and Alter are two SQL (Structured Query Language) commands used for modifying databases. Update statement is used to update existing records in a database. Update is a Data Manipulation Language (DML) statement. Alter SQL command is used to modify, delete or add a column to an existing table in a database. Alter is a Data Definition Language (DDL) statement. Commands that are used to define the structure of a database (database schema) are called DDL statements.

Update is a SQL command that is used to update existing records in a database, while alter is a SQL command that is used to modify, delete or add a column to an existing table in a database.

Update is a DML statement whereas alter is a DDL statement. Alter command modifies the database schema, while update statement only modifies records in a database without modifying its structure

Wednesday, January 16, 2013

FTP Server

FTP Server on RedHat Linux

It is a file transfer protocol, which is use to transfer the file and receive the file from a Central server up to client, it work at application layer of OSI model and port no. is 20 & 21. port no. 20 is used for connectivity and port no. 21 is used for send & receive data.

FTP Important note:-

  •  The configuration file for vsftpd is "/etc/vsftpd/vsftpd.conf"
  •  By default root user can't access ftp server
  •  By default other user can't access ftp server
  •  By default anonymous user can assess ftp server & it need no password.

Server configuration:-


Step-1 install vsftpd package
#yum install vsftpd*
(package is installing from yum server)

Step-2 make changes in vsftpd.conf file

#vim /etc/vsftpd/vsftpd.conf

Step-3 restart ftp service
#service vsftpd restart  (Service on temporary )
#chkconfig vsftpd on (Service on permanent)


Step-4  Make directory as per requirement

#cd /var/ftp/pub
#mkdir upload download
#cat /download file1


Client Configuration:-


Step-1 Now access ftp server

#ftp 172.24.0.56  (change ip address as ftp server ip)
user: anonymous
Password: (No password require)
>cd pub
>cd download
>mget file1 (mget use for multiple file)
or
>get file1 (get use for one file)
>bye (bye use for exit from ftp)
or
>quit
>good bye (Reply from server side)

Thursday, January 10, 2013

Shell Scripting Program

1-. Write a Shell Script that takes a search string and file name from the terminal & displays the results.

read a
read b
word= ‘grep $a $b’
if test ‘echo $word |wc –c’-eq1
then
echo “patern not found”
else
grep $a $b
fi

output-

sh ss1
enter the string to be searched
ashs
enter the file name
ss2

patern not found

2- Write a Shell Script that takes pattern and file name as command line arguments and displays the results appropriately i.e. pattern found/pattern not found.

if test $# -ne 2
then
echo “Invalid no. of arguments”
else
word=’grep $1 $2
if test ‘word | wc –c’ –eq1
then
echo ”pattern not found ”
else
grep $1 $2
echo “pattern found”
fi
fi

output

sh ss2 contents ss12
echo “ \n” content are same second file is being deleted
echo “ \n” content are different

pattern found

3- Write a Shell Script that accepts only three arguments from the command line. The first argument is the pattern string, the second argument is the file name in which the pattern is to be searches and the third argument is the file name in which the result is to be stored.

if test $# -ne3
then echo “Invalid no. of arguments”
else
grep $1 $2 | cat>$3
if test –s $3
then
echo “pattern found”
cat $3
else
echo “pattern not found”
fi

output:

sh ss3 echo ss12 output
pattern found
echo “\n ” content are same second file is being deleted
echo “ \n” content are different
echo “ \n” file does not exist
cat output
echo “ \n” content are different
echo “ \n” file does not exist.

4- Write a Shell Script that accepts a file name as a command line argument and finds out if its a regular file or a directory. If its a regular file, then performs various tests to see if it is readable, writable, executable etc.

if [-d $1]
then
echo It’s a directory
elif  [-f $1]
then
echo file exist
if [-r $1]
then
echo file has read permission
echo the content are ----
cat $1
else
file don’t have read permission
fi
if [-w $1]
then
echo “ ”file have write permission
cat >>$1
else
echo you do not have write permission
fi
if [-x $1]
then
echo “ ” file have execute permission
else
you don’t have execute permission
fi
else
echo Nothing exist by this name
fi

Output:

$ sh ss4 free
file exist
file has read permission
the content are _ _ _ _ _
Ashish is a mca student
__ _ _ _ _ _ _ _

You have execute permission

5- Write a Shell Script that computes the factorial of a given number

echo “Enter the no. to compute its factorial”
read num
i=1
fact=1
while test $i –le $num
do
fact = “factorial of : $num is: $fact”

Output:

 sh ss6
Enter the no. to compute its factorial
6

Factorial of :6 is: 720

6- Write a Shell Script that works like a calendar reminding the user of certain things depending on the day of the week.

a= `date + % A`
echo “\n” welcome Ashish
echo “\n ” Today is $a
echo your task for today is as follows
case $a in
Monday) echo complete ur Monday task
;;
Tuesday) echo complete ur Tuesday task
;;
Wednesday) echo complete ur Wednesday task
;;
Thursday) echo complete ur Thursday task
;;
Friday) echo complete ur Friday task
;;
Saturday) echo complete ur Saturday task
;;
Sunday) echo complete ur Sunday task
;;
Esac

Output:

Sh ss7
Welcome ashish
Today is Sunday
Complete ur Sunday taske

7- Write a Shell Script that changes the extension of a group of files from txt to doc

echo Before
ls *.txt
for i in `ls *.txt`
domv $i `echo $i|cut -f1 -d"."`.doc
done
echo After
ls *.doc

Output :

$sh ss8
Before
d.txt f.txt r.txt
After
d.doc  e?q?w.doc  f.doc  q?w.doc  r.doc  w.doc

8-  Write a Shell Script that accepts both file name and a set of patterns as positional parameters to a script.

 fn=$1
shift
for i in $*
do
grep $i
$fn
done

Output:

ashish@ASHISH-PC:~/File$ sh SS9 ss8 txt doc
ls *.txt
for i in `ls *.txt`
mv $i `echo $i|cut -f1 -d"."`.doc
ls *.doc
ashish@ASHISH-PC:~/File$

9- Write a Shell Script which will redirect the output of the date command without the time into a file.

echo Enter the file name
read file
a=`date|cut -b 1-11,25-28`
echo $a|tee -a $file
clear
echo "\n"$file sucessfully created
echo "\n""Content of file is :"`cat $file`

Output :

sh ss10
Enter the file name
ss2
Thu Nov 20 2008
ss2 sucessfully created

Content of file is :if test $# -ne 2 then echo "Invalid no. of arguments" else word=`grep $1 $2` if test `echo $word|wc -c` -eq 1 then echo "Pattern not found" else grep $1 $2 fi fi Thu Nov 202008

10- Write a Shell Script (using while loop) to execute endlessly (until terminated by user) a loop which displays contents of current directory, disk space status, sleep for 30 seconds and display the users currently logged in on the screen.

char=y
while [ $char ="y" ]
do
ls
df -t
sleep 30
who
echo"Want to continue\(y/n\)?"
read char
done


Output :

sh ss11
cold gold sold ss11 ss14  SS17 ss2 ss22 SS25 SS28 SS30 ss6 SS9
e.txt  output  ss1  ss12  ss15  ss18  SS20 ss23 SS26 SS29 ss4 ss7 tr.c
f1 q.txt ss10 ss13 ss16 SS19 ss21 SS24 SS27 ss3 SS5 ss8 w.txt
Filesystem       1K-blocks         Used                Available  Use%  Mounted on
/dev/sda6        4845056          2476544          2124328    54%      /
varrun                         452316            96                    452220        1%      /var/run
varlock            452316            0                      452316         0%     /var/lock
udev                452316            56                    452260          1%     /dev
devshm            452316           12                    452304            1%   /dev/shm
lrm                  452316           39760              412556            9%   /lib/modules/2.6.24-19-generic/volatile
gvfs-fuse-daemon 4845056    2476544          2124328          54%     /home/ashish/.gvfs
ashish tty7 2008-11-20 11:20 (:0)
ashish pts/0 2008-11-20 11:25 (:0.0)
Want to continue\(y/n\)?

11- Write a Shell Script that receives two file names as arguments. It should check whether content of the two files is same or not. If they are same, second file should be deleted.

if [ -f $1 -a -f $2 ]
then
if diff $1 $2
then
cat $1
echo "\n"
cat $2
echo "\n" Contents are same Second file is being deleted
rm $2
else
echo"\n" Contents are different
fi
else
echo "\n" File does not exist
fi

Output:

$ sh ss12 df rt
Ashish
Ashish
Contents are same Second file is being deleted
$

12 - If a number is input through the keyboard, WASS to calculate sum of its digits.

echo Enter a no.
read num
sum=0
while true
do
if test `expr $num % 10` -gt 0
then
temp=`expr $num % 10`
sum=`expr $sum + $temp`
num=`expr $num / 10`
else
echo $sum
exit
fi

Output:

sh ss13
Enter a no.
2345
14

13-  Write a Shell Script that performs a count-down either from 10 (default) or from the value that is entered by the user.

echo "Enter the Countdown time."
read n
clear
while [ $n -ge 0 ]
do
echo $n
sleep 1
n=`expr $n – 1`
done
echo Count down timer stopped

Output:

sh ss14
Enter the Countdown time.
3
3
2
1
0
Count down timer stopped

14- Write a Shell Script which takes a command line argument of Kms and by default converts that number into meters. Also provide options to convert km to dm and km to cm.

Km=$1
mt=`expr $km \* 1000`
echo "1.) km to dm"
echo "2 ) km to cm"
echo Enter your choice
read num
case $num in
1)dm=`expr $km \* 10000`
echo $km in meters is :$mt and in decimeters is : $dm
;;
2)cm=`expr $km \* 100000`
echo $km in meters is :$mt and in centimeters is : $cm
;;
esac

Output:

sh ss15 5
5 kms in meters is 5000
km to dm
km to cm
Enter your choice
1
5 in meters is- 5000 and in decimeters is 50000

15-  Write a Shell Script using for loop, which displays the message "Welcome to the UNIX System".

for var in $*
do
echo "Welcome to Unix System"
shift 1
done

Output:

sh ss16
Welcome to Unix System

16- Write a Shell Script to change the file name of all files in a directory from lower-case to upper-case.

for i in *
do
mv $i `echo $i|tr "[:lower:]" "[:upper:]"`
done

Output:

sh SS17
mv: `COLD' and `COLD' are the same file
mv: `E.TXT' and `E.TXT' are the same file
mv: `F1' and `F1' are the same file
mv: `GOLD' and `GOLD' are the same file
mv: `Q.TXT' and `Q.TXT' are the same file
mv: `SOLD' and `SOLD' are the same file
mv: `SS1' and `SS1' are the same file
COLD GOLD SOLD SS11 SS14 SS17 SS2 SS22 SS25 SS28 SS30 SS6 SS9
E.TXT OUTPUT SS1 SS12 SS15 SS18 SS20 SS23 SS26 SS29 SS4 SS7 TR.C
F1 Q.TXT SS10 SS13 SS16 SS19 SS21 SS24 SS27 SS3 SS5 SS8 W.TXT

17- Write a Shell Script that examines each file in the current directory. Files whose namesend in old are moved to a directory named old files and files whose names end in .c aremoved to directory named cprograms.

echo Before "\n"
ls -l
mkdir oldfiles cprograms
for var in `ls`
do
if test $var = *old
then
echo "\n" File $var is moved to old files directory
mv $var old files
fi
if test $var = *.c
then
echo"\n" File $var is moved to cprograms directory
mv $var cprograms
fi
done
cd oldfiles
echo "\n" Files in oldfiles
ls -l
cd ..
echo "\n" After"\n"
ls -l

Output:

sh SS18
Before
total 144-rwxrwxrwx 1 ashish ashish 66 2008-11-20 10:07 COLD
-rwxrwxrwx 1 ashish ashish 0 2008-11-20 10:07 E.TXT
-rwxrwxrwx 1 ashish ashish 7 2008-11-20 10:07 F1
-rwxrwxrwx 1 ashish ashish 54 2008-11-20 10:07 GOLD
Files in oldfiles
total 0
After
total 152
-rwxrwxrwx 1 ashish ashish 66 2008-11-20 10:07 COLD
drwxr-xr-x 2 ashish ashish 4096 2008-11-20 12:04 cprograms
-rwxrwxrwx 1 ashish ashish 0 2008-11-20 10:07 E.TXT
-rwxrwxrwx 1 ashish ashish 7 2008-11-20 10:07 F1
-rwxrwxrwx 1 ashish ashish 54 2008-11-20 10:07 GOLD

18- Write a Shell Script which searches all files in the given directory (to be taken as command line argument) for the file having the title (to be taken as command line argument), as the first line in the file.

a) Display the contents of the searched file.
b) In the end, printthe the file is ###, where

### is small-sized if total no. of lines is <50 data-blogger-escaped-span="span">
### is medium-sized if total no. of lines between 50&100
### is large-sized.
for i in `ls $dirnm`
do
f=`echo $1/$i`
if [ -f $f ]
then
if [ `cat $f|head -1` = $2 ]
then
cat $f
if [ `cat $f|wc -l` -lt 50 ]
then
echo $i is small sized
fi
if [ `cat $f|wc -l` -ge 50 -a `cat $f|wc -l` -lt 100 ]
then
echo $i is a medium sized
fi
if [ `cat $f|wc -l` -gt 100 ]
then
echo $i is large sized
fi
fi
fi
done

Output:

sh ss19 newdir AMITY
AMITY
Amity University
file1 is small sized

19- Write a shell script which reports names and sizes of all files in a directory (directory would be supplied as an argument to the shell script) whose size is exceeding 1000 bytes.The file names should be printed in descending order of their sizes. The total number of such files should also be reported.

Cd $1
mkdir
tmp$1
for i in *
do
if [ -f $i ]
then
tmp=`ls -l $i|cut -f5 -d" "`
if [ $tmp -gt 1000 ]
then
ln $i tmp$1/$i
fi
fi
done
ls -lS tmp$1
echo Total number of such files is : `ls tmp$1|wc -w`
rm -r tmp$1

output:

sh SS20
total 4-rw-r--r-- 2 ashish ashish 1392 2008-11-20 11:02 unix output
Total number of such files is : 1

20- WASS for renaming each file in the directory such that it will have the current shell PID as an extension. The shell script should ensure that the directories do not get renamed.

for var in `ls`
do
if test -f $var
then
a=`echo $$`
mv $var $var.$a
fi
done
echo "\n" File name changed:"\n"
ls -l

Output:

sh SS21.7600.a
File name changed:
total 152
-rwxrwxrwx ashish ashish 66 2008-11-20 10:07 COLD.7600.a.a
drwxr-xr-x 2 ashish ashish 4096 2008-11-20 12:04 cprograms
-rwxrwxrwx 1 ashish ashish 0 2008-11-20 10:07 E.TXT.7600.a.a
-rwxrwxrwx 1 ashish ashish 7 2008-11-20 10:07 F1.7600.a.a
-rwxrwxrwx 1 ashish ashish54 2008-11-20 10:07 GOLD.7600.a.a
drwxr-xr-x 2 ashish ashish 4096 2008-11-20 12:04 oldfiles


21- WAP to calculate and print the first m Fibonacci numbers.

echo Enter the series length
read num
x=0
y=1
if test $num -eq 1
then echo $x
else if test $num -eq 2
then echo "$x\n$y"
else
echo "$x\n$y"
i=3
while test $i -le $num
do
temp=`expr $y + $x`
x=$y
y=$temp
echo $y
i=`expr $i + 1`
done
fi
fi

Output:

sh SS22
Enter the series length
6
0
1
1
2
3

22- WASS that will receive any number of file names as arguments. The shell script should check whether such files already exist. If they do, then it should be reported. The files that do not exist should be created in a sub-directory called my dir. The shell script should first check whether the sub-directory my dir exists in the current directory. If it doesn’t exist,then it should be created. If my dir already exists, then it should be reported along with the number of files that are currently present in my dir.

if [ -e mydir ]
then
echo "Directory : mydir exist"
else
echo Do not exist
mkdir mydir
fi
for a in $*
do
echo $a
then
echo "File does not exist "
else
echo “file d
touch $a
mv $a mydir
fi
done

Output:

sh SS23 SS22
Directory : mydir exist
SS22
File does not exists

23-  A shell script receives even number of file names. Suppose four file names are supplied,then the first file should get copied into second file, the third file should get copied into fourth and so on. If odd number of file names is supplied then no copying should take place and an error message should be displayed.

if [ `expr $# % 2` -ne 0 ]
thenecho Enter even number of parameters
else
i=0
for k in $*
do
i=`expr $i + 1`
if [ $i -eq 1 ]
then
temp1=$k
fi
if [ $i -eq 2 ]
then
temp2=$k
i=0
cp $temp1 $temp2
fi
done
fi
cat

Output:

$ cat>txt
File Ashish lives in Delhi$ cat>doc
Ashish is a student of MCA$ cat>tree
Ashish is a good student$ cat>wee
His roll no- is A1004807024
$ sh SS24 txt doc tree wee
His roll no- is A1004807024 Ashish is good student Ashish lives id Delhi Ashish is a student of BCA


24- WASS to identify all zero-byte files in the current directory and delete them. Before proceeding with deletion, the shell script should get a conformation from the user.

for i in *
do
if [ -e $i -a -f $i ]
then
if [ -s $i ]
then
echo
else
rm -i $i
fi
fi
done

Output:

sh SS25
rm: remove regular empty file `E.TXT'?  y
rm: remove regular empty file `Q.TXT'?  n
rm: remove regular empty file `W.TXT'? n

25- WASS to compute the GCD and LCM of two numbers.

echo Enter First number
read n1
echo Enter Second number
read n2
if [ $n1 -lt $n2 ]
then
i=$n1
else
i=$n2
fi
flag=0
while [ $flag -eq 0 ]
do
if [ `expr $n1 % $i` -eq 0 -a `expr $n2 % $i` -eq 0 ]
then
echo GCD of $n1 and $n2 is $i
flag=1
fi
i=`expr $i – 1`
done

Output:

sh SS26
Enter First number
4
Enter Second number
8
GCD of 4 and 8 is 4

26- Two numbers are entered through the keyboard. WAP to find the value of one number raised to the power of another.

read b
echo Enter power
read p
powr=$p
result=1
while [ $p -ge 1 ]
do
result=`expr $result \* $b`
p=`expr $p – 1`
done
echo $b raised to the power $powr is $result

Output:

sh SS27
Enter a number
4
Enter power
2
4 raised to the power 2 is 16

27- WASS that prompts the user for the password. The user has maximum of 3 attempts. If the user enters the correct password, the message “Correct Password” is displayed else the message “Wrong Password”.

echo Set the password first
read passw
i=0
while [ $i -lt 3 ]
do
echo Enter password
read p
if [ $p = $passw ]
then
echo Correct Password
i=3
else
echo Wrong password
i=`expr $i + 1`
fi
done

Output:

sh SS28
Set the password first
ashish
Enter password
ashish
Correct Password

28-  WASS that repeatedly asks the user repeatedly for the “Name of the Institution” until the user gives the correct answer.

Flag=0
while [ $flag -eq 0 ]
do
echo Enter name of your institute in capital letters
read inst
if [ $inst = "AMITY" ]
then
echo Correct Answer
flag=1
else
echo Enter Again
fi
done

output:

sh SS29
Enter name of your institute in capital letters
AMITY
Correct Answer

29-  WAP to generate all combinations of 1, 2 and 3 using for loop.

for i in 1 2 3
do
for j in 1 2 3
do
for k in 1 2 3
do
echo $i$j$k
done
done
done

Output:

sh SS30
111
112
113
121
122
123
131
132
133
211
212
213
221
222
223
231
232
233
311
312
313
321
322
323
331
332
333