Scripting (Just one of many tools.) P. Bailey. No, not this kind of scripting….  I wanted to find some cool graphics on scripting and I got…. https://www.youtube.com/watch?v=6iVfXj7aojs.

Slides:



Advertisements
Similar presentations
Debugging ACL Scripts.
Advertisements

7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell 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.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Shell Script Examples.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
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.
Sydney Opera House. Week Three Agenda Administrative Issues Link of the week Review week two lab assignment This week’s expected outcomes Next lab assignment.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
System Programming Regular Expressions Regular Expressions
Exam Revision. Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part?
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
A Guide to Unix Using Linux Fourth Edition
Day 8 Exporting Displays Cronjobs Mount. Chapter 5 Chapter 5 talks about X windows. –You should read the chapter. –However, you do not need to pay particular.
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Essential Shell Programming by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
BY Sandeep Kumar Gampa.. What is Regular Expression? Regex in.NET Regex Language Elements Examples Regular Expression API How to Test regex in.NET Conclusion.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Sys Prog & Scrip - Heriot Watt Univ 1 Systems Programming & Scripting Lecture 12: Introduction to Scripting & Regular Expressions.
40 Years and Still Rocking the Terminal!
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Introduction to Programming Using C An Introduction to Operating Systems.
Regular Expressions CS 2204 Class meeting 6 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
UNIX Shell Dr. Tran, Van Hoai
Advanced Programming in the UNIX Environment Hop Lee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Basic UNIX Concepts. Why We Need an Operating System (OS) OS interacts with hardware and manages programs. A safe environment for programs to run is required.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Module 1 - Introduction to Linux. Users must log-in Linux is case sensitive File and Directories naming conventions (No spaces!) Files and Directories.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Linux+ Guide to Linux Certification, Second Edition
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
Pattern Matching: Simple Patterns. Introduction Programmers often need to scan a file, directory, etc. for a specific substring. –Find all files that.
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.
Running the Operational Codes for the Brahmaputra Tom Hopson.
Linux Administration Working with the BASH Shell.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
UNIX UNIX tools Automating LIS Administration
SUSE Linux Enterprise Desktop Administration
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Sydney Opera House.
Unix Scripting Session 4 March 27, 2008.
Henning Schulzrinne Advanced Programming
What is Bash Shell Scripting?
An Introduction to UNIX System --- Cosc513 Presentation
Chapter Four UNIX File Processing.
Linux Shell Script Programming
Week 1 – Lesson 2: Creating Shell Scripts, Linux Commands
Presentation transcript:

Scripting (Just one of many tools.) P. Bailey

No, not this kind of scripting….  I wanted to find some cool graphics on scripting and I got….

Concept of a Shell Hardware Kernel SHELL vi grepawk ls who another shell df netstat diff

Scripting Languages  Plain-text files  Interpreted – Not Compiled  Tie together tools  Usually and imperative language with flow control  Form of job control  The “glue”: coordinate the calls to applications A scripting or script language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Wikipedia:

UNIX Scripting  Common languages: bash, K-Shell, C- Shell, perl, awk  Bash, ksh etc have meta-character support  Heavy use in /etc (the home for a system administrator  Example: /etc/rc0.d

UNIX Scripting Languages  Must have both read and execute permission myscript.sh -r-wr-wr-w Should be myscript.sh –r-xr-xr-x (or –rwx-r-xr-x)  Why not just execute?

Windows Scripting Languages . BAT files. Originally from MSDOS,very limited. Environment variables identified by percent signs (E.G. %PATH%) … UGH!  VB Script. Like VBA and VB. Very flexible (e.g. supports regular expressions)  Powershell. Combines the strongest features of other languages..Net support and object based. (*still doesn’t have meta-characters) Has an execution policy.

Interpreted Ajouter un œuf. “Add one egg Add flour” INTERPRETER Ajouter la farine

Compiled Ajouter un œuf. COMPILER Add one egg. Add 1 cup flour

Discussion question…(get a piece of candy) Compiled applications only need the “interpretation” once. Then, they are directly executable. Why not use compiled languages more often instead of scripting?

Use of Environment  System level  Application level (usually taking precedence)  Passed on to applications called in script  The environment includes:  Current working path  Variables (Path, LIBPATH, $SHELL)  Current process information (e.g. process Id)  Etc.

Process (Applies to Windows and UNIX)  A process is an instance of an application running.  Each process is uniquely identified by its ID  A process can create another process (child process)  A process gets a copy of the environment from its parent process

Process implications  Placing environment variables in a script is not enough because calling the script only creates a sub-process  For the environment variables in a separate script to change the current process, it must be dot-sourced Example:. /path/myenv.sh. /path/myenv.ps1

Handy Tool: Regular Expressions In theoretical computer science and formal language theory, a regular expression (sometimes called a rational expression ) [1][2] is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations.theoretical computer scienceformal language theory [1][2]characterspattern matchingstringsstring matching

Basics of RE MCharDefinition ^Start of a string. $End of a string..Any character (except \n newline) |Alternation. {...}Explicit quantifier notation. [...]Explicit set of characters to match. (...)Logical grouping of part of an expression. *0 or more of previous expression. +1 or more of previous expression. ? 0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string. \ Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below.

Sample Patterns PatternSample Matches ^abcabc, abcdefg, abc123,... abc$abc, endsinabc, 123abc,... a.cabc, aac, acc, adc, aec,... bill|tedted, bill ab{2}cabbc a[bB]cabc, aBc (abc){2}abcabc ab*cac, abc, abbc, abbbc,... ab+cabc, abbc, abbbc,... ab?cac, abc a\sca c

Problem  Write a regular expression that matches any line in a log file that indicates a failed status of some type for an installation such as the first line in the example below: :19:33: e00 COMAPI - Install call complete (succeeded = 1, succeeded with errors = 0, failed = 0, unaccounted = 0) :53:21: ky27 Agent- Install success 'Install.*failed =.+'

Startup Scripts  Startup scripts exist to ensure that the “environment” is setup before running an application.  The environment can include  the directory where the application starts  environment variables that the application uses to determine run time features  Startup scripts also can log the successful launch or shutdown of an application

Job Control  “Job” is a term historically associated with scheduled operations.  A Job Control language defines dependencies (e.g. On success of Job A, run Job B, otherwise run Job c)  Scripting in UNIX and Windows are the low cost alternative to Job Control

UNIX Scheduling with cron # minute (0 - 59) # | hour (0 - 23) # | | day of month (1 - 31) # | | | month (1 - 12) # | | | | day of week (0 - 6) (Sunday=0 or 7) # | | | | | * * * * * command to be executed # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.XXXXfoPWZt installed on Thu Nov 15 09:42: ) # (Cron version V $Id: crontab.c,v /01/23 18:56:42 vixie Exp $) #first entry * * * /home/pmb4/IS271/scripting/scripts/nightlyrun.sh EXAMPLE

Windows Scheduling

Lab Preparation  Review basic concepts at lt.aspx (if, while and foreach) lt.aspx  Read Chapter 18: WMI from above.  Review us/library/windows/desktop/aa394595%28v=vs.8 5%29.aspxhttps://msdn.microsoft.com/en- us/library/windows/desktop/aa394595%28v=vs.8 5%29.aspx