Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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

2 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

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

4 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: https://en.wikipedia.org/wiki/Scripting_languagehttps://en.wikipedia.org/wiki/Scripting_language

5 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

6 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?

7 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.

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

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

10 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?

11 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.

12 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

13 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

14 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 https://en.wikipedia.org/wiki/Regular_expression

15 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.

16 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

17 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: 2016-04-23 19:19:33:932 6204 1e00 COMAPI - Install call complete (succeeded = 1, succeeded with errors = 0, failed = 0, unaccounted = 0) 2016-04-23 19:53:21:811 6277 ky27 Agent- Install success 'Install.*failed =.+'

18 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

19 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

20 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:42 2007) # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) #first entry 43 10 * * * /home/pmb4/IS271/scripting/scripts/nightlyrun.sh EXAMPLE

21 Windows Scheduling

22 Lab Preparation  Review basic concepts at http://powershell.com/cs/blogs/ebookv2/defau lt.aspx (if, while and foreach) http://powershell.com/cs/blogs/ebookv2/defau lt.aspx  Read Chapter 18: WMI from above.  Review https://msdn.microsoft.com/en- 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


Download ppt "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."

Similar presentations


Ads by Google