Part I: n Q1: n $ file * | grep “ascii text” | wc -l n Q2: n $ a.out | tee logfile n Q3: $touch file.`date +’%H%M%S’` n.

Slides:



Advertisements
Similar presentations
Shell Scripting Printing; Loops and Logic printf: formatted print printf is a more standardized method to print text to the screen. It can be used instead.
Advertisements

Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Basics of Shell Programming. What’s Shell? It’s acts an interface between the user and OS (kernel).It’s known as “ command interpreter”. When you type.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Integer variables #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current.
Information Networking Security and Assurance Lab National Chung Cheng University 1 if condition Condition is defined as: "Condition is nothing but comparison.
More Shell Programming Learning Objectives: 1. To learn the usage of environment (shell) variables in shell programming 2. To understand the handling of.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Shell Programming. Shell Scripts (1) u Basically, a shell script is a text file with Unix commands in it. u Shell scripts usually begin with a #! and.
Shell Script Examples.
Shell Control Structures CSE 2031 Fall August 2015.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
CMPSC 60: Week 6 Discussion Originally Created By: Jason Wither Updated and Modified By: Ryan Dixon University of California Santa Barbara.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
Shell scripting. Number check vi isnump_n #!/bin/sh # # Script to see whether argument is positive or negative # if [ $# -eq 0 ] then echo "$0 : You must.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
BASH Scripting A beginners guide to Bourne Again SHell scripting.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
Linux File System and The Shell Yonglei Tao. Linux File System  Consists of one or more self-contained file management units  each is known as a filesystem.
A Menu-Driven Application Yonglei Tao. Problem Statement  Develop a script program that allows the user to create and maintain an directory, called.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Lecture 2: Advanced UNIX, shell scripts (ol)‏ Programming Tools And Environments.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CSCI 330 UNIX and Network Programming Unit IX: Shell Scripts.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
CISC3130 Spring 2013 Fordham Univ. 1 Bash Scripting: control structures.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Shell Control Statements and More
UNIX Shell Script (2) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Sed. Class Issues vSphere Issues – root only until lab 3.
If condition1 then statements elif condition2 more statements […] else even more statements fi.
Group, group, group One after the other: cmd1 ; cmd2 One or both: cmd1 && cmd2 Only one of them: cmd1 || cmd2 Cuddling (there):( cmd1 ; cmd2 ) Cuddling.
UNIX commands Head More (press Q to exit) Cat – Example cat file – Example cat file1 file2 Grep – Grep –v ‘expression’ – Grep –A 1 ‘expression’ – Grep.
Various 2. readonly readonly x=4 x=44 #this will give an error (like what in java?)
2 nd Intro to Shell Scripting. Dates for Last Week of Class Homework 7 – Due Tuesday 5/1 by midnight Labs 7 & 8 or late ones – 8 is extra credit – Due.
Experiment No. 13 Presented by, Mr. Satish Pise. Write a shell script which checks disk space and store the value to the variable and display it. #!/bin/sh.
By Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Linux Essentials Chapter 12: Creating Scripts. Chapter 12 Outline Beginning a shell script Using commands Using arguments Using variables Using conditional.
Shell Control Structures CSE 2031 Fall June 2016.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Computer Programming Batch & Shell Programming 9 th Lecture 김현철 컴퓨터공학부 서울대학교 2009 년 가을학기.
Bash Shell Scripting 10 Second Guide.
Shell Control Structures
CSC 352– Unix Programming, Fall 2012
Part 1: Basic Commands/Utilities
Unix Scripting Session 4 March 27, 2008.
Shell Script Assignment 1.
What is Bash Shell Scripting?
Pepper (Help from Dr. Robert Siegfried)
Unix Scripting Dave Yearke
UNIX Reference Sheets CSE 2031 Fall 2010.
awk- An Advanced Filter
CSC 352– Unix Programming, Fall, 2011
Essential Shell Programming
Introduction to Bash Programming, part 3
Review.
Unix Scripting Session 2 March 13, 2008.
Presentation transcript:

Part I: n Q1: n $ file * | grep “ascii text” | wc -l n Q2: n $ a.out | tee logfile n Q3: $touch file.`date +’%H%M%S’` n

Part I: n Q4: n Solution 1: n $ find -size exec rm -i {} \; solution 2: n $ rm -i `ls -l | awk ‘ /^-/ {if ($4 > 1024) printf(“%s”,$8);}’`

Part I: n Q5: n $ last | grep “`date | cut -d’ ‘ -f2,3” ` | n awk `$7>=“08:00” {print $1” ` n Q6: n $ grep mypals myfile > /dev/null && n mail `grep mypals myfile | cut -d: -f2`

Part I: n Q8: Solution 1: n $ ls -t `grep -l main \`file * | grep ascii | cut -d: -f1 \` 2> /dev/null ` n Solution 2: n grep -l string `file *.* | grep text | cut -d: - f1` | xargs ls -t

No one in the class work out Q7 correctly n Q7: n $ awk ‘/^$/ {print; turn=0; while (getline >0 && length($0) == 0){ turn = 1-turn; if (turn) print; } printf(“%s”,$0);} n /./ {printf(“%s”,$0); while (getline >0 && length($0) >0) printf(“%s”,$0); printf(“\n”); }’ date.txt

Part II Command line parsing n #/bin/sh n showdir=0 n showfile=0 n while [ $# -gt 0 ] n do n case $1 in n -h)echo "lc [-f] [-d] [dir]" n echo "-f: list only files" n echo "-d: list only subdirectories" n exit 1 n ;; n -f)showfile=1 ;; n -d)showdir=1 ;; n -*)echo "Bad option :" $1 n exit 1;; n *)break n ;; n esac n shift n done

Part II: Continue command line parsing n if [ ${showfile} -eq 0 -a ${showdir} -eq 0 ] n then n showfile=1 n showdir=1 n fi n curdir=${1-.} n test -x $curdir || ( echo "Can't chdir to" $curdir && exit 1 )

Part II: main body n ls -l $curdir | awk -F' ' '$1 ~ /^[d-].*/ { printf("%s\t%s\n",$1,$8);}' |\ n nawk -v showfile=$showfile -v showdir=$showdir \ n ' n function output(title,arr,no){\ n printf("%s\n",title);\ n for(i=0;i<no;i++){\ n printf("%-10s ",substr(arr[i],0,10));\ n if(i%6==5)\ n printf("\n");\ n }\ n printf("\n");\ n }\ n BEGIN { countfile=0;countdir=0} \ n $1 ~ /^d.*/ { if( showdir ) dirs[countdir++]=$2; } \ n $1 ~ /^[^d].*/ { if( showfile ) files[countfile++]=$2; } \ n END { n if (showdir) \ n output("Directories:",dirs,countdir);\ n if(showfile)\ n output("\nFiles:",files,countfile);\ n }'