2 nd Assignment  Improve Toyshell with some new feature, such as: help, cd, ctrl/D, setenv and compile it. Create a user “lapsa” and make him to get Toyshell.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Appendix A. Man Pages man whatis whatis(1) Typical Man Page Sections SectionContents User commands System calls C library functions.
Linux+ Guide to Linux Certification, Second Edition
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Guide To UNIX Using Linux Third Edition
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP 229, 346, 444, 5201 Revision 1.3.
Shell Script Examples.
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
Shell Control Structures CSE 2031 Fall August 2015.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Introduction to Shell Script Programming
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Introduction to UNIX / Linux - 11
Simple Shell Part 1 Due date (75%): April, 2002 Part 2 Due date (25%): Apr 5, 2002.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Lecture 3: Unix installation&testing Guntis Barzdins Girts Folkmanis Juris Krumins.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
CS465 - UNIX The Bourne Shell.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Creating and Executing Processes
ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner.
1 P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming (2) Ruibin Bai (Room AB326) Division of Computer Science The University.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Process Management Azzam Mourad COEN 346.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Linux+ Guide to Linux Certification, Second Edition
Agenda The Bourne Shell – Part I Redirection ( >, >>,
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
Linux Administration Working with the BASH Shell.
Shell Control Structures CSE 2031 Fall June 2016.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
Implementation of a simple shell, xssh
Implementation of a simple shell, xssh
CSE 303 Concepts and Tools for Software Development
Writing Shell Scripts ─ part 3
Engineering Innovation Center
Programming Assignment 1
Simple Shell Due date: March 27, 2002.
Linux Shell Script Programming
Chapter 3 The UNIX Shells
Presentation transcript:

2 nd Assignment  Improve Toyshell with some new feature, such as: help, cd, ctrl/D, setenv and compile it. Create a user “lapsa” and make him to get Toyshell upon login.  Write 4 small shell scripts specified  Explain some Unix shell script (e.g. some strat-up sequence script) with total length >30 lines What is the role of this script in the Unix system? Comment the contents of the script line by line  (Optional): replace Unix “init” program with some other program (e.g. shell) and manually bring the system to usable state Record your manual steps into a shell-script and use it to initialize the system automatically after restart (without the classic “init”)

Submission  Name your submission JanisBerzins.zip  Name shell scripts 1.sh, 2.sh, 3.sh, 4.sh To ease their automatic verification by teacher

Technical info  Recommended is Bash; if you use a different shell language, make sure that we will be able to run it  Scripts can use external “helper” programs, but do not use any exotics that the testing system might not have  Scripts must not ask for any other input than specified or pause as they may be tested automatically  Of course, no abuse attempts  Toyshell can be (optionally) improved with fragments from file found under 4. lekcija – “ Noderīgi progr.fragmentu paraugi” or by looking at some real shell source code

1.sh  Create script, that automatically writes “hello world” to standard output deletes file “deleteme.txt” creates directory “new_dir” in the working directory writes the output of “date” command to file “date.txt” inside the “new_dir” directory

2.sh  File “a” will contain one number 0 <= A <= 100  File “b” will contain one number 0 <= B <= 100  Create Bash script, that will read inputs from files and create file “c” containing number A*B (A multiplied by B)  Example: If file “a” contains “4”, file “b” contains “5”, and “./2.sh” is run, file “c” should contain “20”.

3.sh  Create script, that will take 2 arguments: 3.sh  Search the files in for substring “moveme” in the file content  Move those files that contain the string to directory  On the standard output, output two lines: On first line, output the total number of lines that matched On second line, output the total number of files moved

4.sh  Create a number guessing game, that “thinks” of a number N in the range of and makes the user guess it  Read user’s guess (internal command read )  After successful attempt, show victory message and exit  After unsuccessful attempt, show number of tries left, and whether the number guessed is larger or smaller than N  If 10 tries are made, display N and exit

#include #define MAXLINE 200 #define MAXARG 20 extern char **environ; void env(void){ int i; for(i=0;environ[i]!=NULL;i++){ printf("%s\n",environ[i]); } void exitsh(int status){ _exit(status); } void execute(char *arg[]){ pid_t pid; int status; pid=fork(); if(pid>0){ wait(&status); } else if (pid==0) { execvp(arg[0],arg); printf("Komanda nav atrasta\n"); exitsh(0); } else { printf("Kluda fork() sistemas izsaukuma\n"); } int main (void){ char cmd[MAXLINE]; char *cmdp; char *av[MAXARG]; int i; while(1){ printf("$toyshell$> "); fgets(cmd,sizeof(cmd),stdin); if(strcmp(cmd,"env\n")==0){ env(); } else if(strcmp(cmd,"exit\n")==0){ exitsh(0); } else { cmdp=cmd; for(i=0;i<MAXARG;i++){ av[i]=strtok(cmdp," \t\n"); cmdp=NULL; } execute(av); } return(0); } toyshell.c

“toyshell” palaišana # /usr/bin/gcc toyshell.c # cc toyshell.c #./a.out $toyshell$> env USER=root HOME=/root TERM=vt100 PATH=/root/bin:/usr/local/bin:/bin:/usr/bin SHELL=/bin/sh $toyshell$> ps PID TTY TIME CMD 126 co 0:00 -sh 95 c1 0:00 getty 435 p1 0:00./a.out 436 p1 0:00 ps $toyshell$> exit #