week four agenda

45

Upload: keegan-washington

Post on 30-Dec-2015

19 views

Category:

Documents


2 download

DESCRIPTION

Week Four Agenda. Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines Lab assistance, questions and answers. Announcements. Script Comments Scripts should contain the following comments: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Week Four Agenda
Page 2: Week Four Agenda

Week Four Agenda•Announcements•Link of the week•Review week three lab assignment•This week’s expected outcomes•Next lab assignment•Break-out problems•Upcoming deadlines•Lab assistance, questions and answers

Page 3: Week Four Agenda

AnnouncementsScript Comments

Scripts should contain the following comments:

Editing Author:

Script Functionality:

Lab Assignment:

Due Date:

Page 4: Week Four Agenda

Link of the Week

Object Code • https://freedom-to-tinker.com/blog/felten/source-code

-and-object-code

• What is object code?• http://www.linfo.org/object_code.html• Object File Format

Page 5: Week Four Agenda

Link of the Week

SourceFile

SourceFile

SourceFile

SourceFile

SourceFile

Object File

Object File

ObjectFile

Object File

ObjectFile

LinkerRuntimeLibrary

ExecutableProgram

Source/Object/Executable Drawing

Page 6: Week Four Agenda

Link of the Week

Page 7: Week Four Agenda

Review Week Three Lab Assignment

Textual (command-line) and visual interfaces (graphical) are two common interfaces used to support engineering tasks on systems. Both utilize Netflows data as the main resource.

Netflows are network-based logs that are collected from a network ‘s router. They provide records of the flows that occur on the network. A Netflow record contains a wide variety of useful information about the traffic in a given flow.

Page 8: Week Four Agenda

Review Week Three Lab Assignment

SolarWinds NetFlow Traffic Analyzer (NTA) analyzes Cisco NetFlow, Juniper J-Flow, IPFIX, sFlow, & Huawei NetStream™ data to deliver a complete picture of network traffic, identifying who and what are consuming your bandwidth.

Page 9: Week Four Agenda

Review Week Three Lab Assignment

What is a filter?A UNIX filter command performs an operation or manipulation of the input text from a file. Standard in and out are typically used during this operation.

UNIX Command Line Filters

awk, cat, cut, expand, compress, fold, grep, head, nl, perl, pr, sed, sh, sort, split, strings, tail, tac, tee, tr, uniq, and wc

Page 10: Week Four Agenda

Review Week Three Lab AssignmentFile System Filters

cat, cd, chmod, chown, chgrp, cksum, cmp, cp, dd, du, df, fsck, fuser, ln, ls, lsattr, lsof, mkdir, mount, mv, pwd, rm, rmdir, split, touch, umask

 

Processes Filters

at, chroot, cron, exit, kill, killall, nice, pgrep, pidof, pkill, ps, pstree, sleep, time, top, and wait

Page 11: Week Four Agenda

Review Week Three Lab Assignment

Test CommandA common way to set up a condition for the if command is with the test command.

test condition or [ condition ]

The test command evaluates the condition and returns 0 or 1, depending on the results of the test.The brackets work exactly like the test condition. The open bracket is a link to test.

Page 12: Week Four Agenda

Review Week Three Lab Assignment

Constructing Conditions-s file -r file -w file -S file-x file -f file -d file

Examples: if [ ! –f /etc/.fsckask ]If the plain file /etc/.fsckask does not exist

If [ -d /etc/rc0.d ]If there is a directory named /etc/rc0.d

Page 13: Week Four Agenda

Review Week Three Lab Assignment

Perl is a simple language that compiles and executes like a shell or batch type file.

Perl doesn’t impose special growth limitations on an array or data strings

Perl is a composite of C, AWK, and Basic.

Perl was originally developed to manipulate text information.

Page 14: Week Four Agenda

Review Week Three Lab Assignment• Perl’s capabilities range from

- System administration- Web development- Network programming- GUI development

• Perl’s major features are- Procedural Programming makes use of simple

sequential steps, routines, subroutines, and methods.

- Object Oriented Programming (OOP) makes use of “objects”. The key elements of are inheritance, modularity, polymorphism, and encapsulation.

Page 15: Week Four Agenda

Review Week Three Lab AssignmentPerl and Shell SimilaritiesPerl scalar@ARGV ~ Shell $#Perl $ARGV[0] ~ Shell $1Perl $ARGV[1] ~ Shell $2Perl unless(scalar(@ARGV)==2) ~ Shell if [ $# != 2]All Perl statements are terminated with a “;”Perl exit 0 is returned if execution was

successful.Perl exit 1 is returned if execution fails.

Page 16: Week Four Agenda

Review Week Three Lab AssignmentPerl syntax$? - this variable contains the return value # - precedes a comment statement in Perl\n - new line syntax“ …” $strexp = “This text is considered as a

string”;‘ …’ $charexp = ‘a’;` …` $cmdexp = `ls –l`;@ARGV – array containing command line

arguments$_ - default implied scalar

Page 17: Week Four Agenda

Review Week Three Lab Assignment

There are two types of relational operators. One class operates on numeric values, the other on string values.

Relational operators

Numeric String Meaning

> gt Greater than

>= ge Greater than or equal

< lt Less than

<= le Less than or equal

Page 18: Week Four Agenda

Review Week Three Lab Assignment

Equality Operators

Numeric String Meaning

== eq Equal to

!= ne Not equal to

cmp Comparison, sign results

-1 if the left operand is less

0 If both operands equal

1 If the left operand is greater

Page 19: Week Four Agenda

Review Week Three Lab Assignment

Commands

cal –y (display a calendar for the year)

cal –j 2010 (display Julian dates)

cal –m 2010 (display Monday first day)

cal –s 2010 (display Sunday first day)

cal 9 2010 (display September 2010 month)

Page 20: Week Four Agenda

Review Week Three Lab Assignment

Umask Calculation

Umask setting = 027

Complement of umask = 750

File default permission setting = 666

Directory default permission setting = 777

The resultant permissions are calculated via bitwise AND of the unary complement of the argument (using bitwise NOT) and the permissions specified by the program.

Page 21: Week Four Agenda

Week Four Expected OutcomesLearning Outcomes• Write Perl scripts, including variables, control

flow, and regular expression syntax

Page 22: Week Four Agenda

Next Lab Assignment

• Perl is designed to

- Process text data

- Perform pattern matching

- Utilize string handling tasks• Perl is available on many platforms

- UNIX

- Linux

- HP-UX

Page 23: Week Four Agenda

Next Lab Assignment

Perl utilizes two types of categories Singular variables that represent a

single- value. The variable prefix symbol for a scalar is the $.

Plural variables are ones that contain multiple-values. Arrays and hashes are two multi-valued variables. The variable prefix symbol for an array and hash are @ and

%, respectively.

Page 24: Week Four Agenda

Next Lab Assignment

Perl data types $answer = 42; (an integer) $pi = 3.14159265; (a “real” number)

$animal = “horse”; (string) $statement = “I exercise my $animal”;

(string with interpolation) $amount = ‘It cost me $5.00’;

(string without interpolation)

$cwd = `pwd`; (string output from a command)

Page 25: Week Four Agenda

Next Lab AssignmentInitialize Perl array:

Definition: An array is an ordered list of scalars, accessed by the scalar’s position in the list.

@garage = (“car”, “mower”, “broom”);

@persons = (“Will”, “Karim”, “Asma”, “Jay”);

$count = @persons;

Extecute Perl script:

./week_four.pl

Page 26: Week Four Agenda

Next Lab AssignmentOpen Statement

The open function can be used to create file handles for different purposes (input, output, and piping), you need to be able to specify which behavior you want.

Page 27: Week Four Agenda

Next Lab Assignmentopen functions

open(file_handler, “file_name”)

open(file_handler, “<file_name”)

open (file_handler, “>file_name”)

open (file_handler, “>>file_name”)

See page 21 in your Perl text.

Page 28: Week Four Agenda

Next Lab AssignmentFilehandle is utilized for both input and output files.

Most file names are cryptic and are meaningless to programmers. The purpose of a filehandle is to help the programmer remember a simple file name throughout a program.

A filehandle is a name given for a file, device, socket, or pipe.

Filehandle command line format:open(filehandle, file name, permissions,

chmod);

Example: open($FH,$file_name);

Page 29: Week Four Agenda

Next Lab AssignmentIf you want to read text from a file line-by-line, then

use the following syntax: my @lines = <FILE>;

The <FILE> operator - where FILE is a previously opened filehandle - returns all the unread lines of the text file in list context or a single line in scalar context. Hence, if you had a particularly large file and you wanted to conserve memory you could process it line by line:

while (<FILE>) { print $_;

}

Page 30: Week Four Agenda

Next Lab AssignmentPerl Formats

if ( … ){

…}

while ( … ){

…}

Page 31: Week Four Agenda

Next Lab AssignmentPerl Formats

for ( initialize variable, test variable, increment variable){

…}

Page 32: Week Four Agenda

Next Lab AssignmentPerl Formats

if ($append) { open(MYOUTFILE, ">filename.out");

#open for write, overwrite }else { open(MYOUTFILE, ">> filename.out");

#open for write, append }

Page 33: Week Four Agenda

Next Lab AssignmentWhat is List Processing?

@math_array = (6 - 4, 4 * 4, 8 / 2, 9 - 8);while ( … ) {

…}

Page 34: Week Four Agenda

Next Lab AssignmentWhat is a for loop?

for (counter = 0; counter < 10; counter++) {

…}

Three expressions are contained in a for loop: 1. Set initial state of the loop variable 2. Condition test the loop variable 3. Modify the state of the loop variable

Page 35: Week Four Agenda

Next Lab AssignmentForeach Statement Format

foreach VAR (List){

…}

Read a list of valuesExecute Perl script:

./read_list.pl

Page 36: Week Four Agenda

Next Lab AssignmentForeach Statement Format@myNames = ('Larry', 'Curly', 'Moe');foreach (@myNames)

{print $_;

}

Sum the elements in an array Execute Perl script:

./sum_list.pl

Page 37: Week Four Agenda

Next Lab AssignmentDisplay the content of an array

Execute Perl script:./array_display.pl

Sort the elements in an array

Execute Perl script:./array_sort.pl

Page 38: Week Four Agenda

Next Lab AssignmentRegular ExpressionsDefinition: Regular expression provides a concise and

flexible means for "matching" (specifying and recognizing) strings of text, such as particular characters, words, or patterns of characters. Abbreviations for "regular expression" include "regex" and "regexp". The concept of regular expressions was first popularized by utilities provided by Unix distributions, in particular the editor “ed” and the command/filter grep.

Example: if ( /UNIX V5/ ) {print “UNIX V5 found on system. \n”;}

Page 39: Week Four Agenda

Next Lab AssignmentRegular Expressions

Substitution operator: s/original value/new value/Character class: Matches a single character that is contained within the brackets [ a-zA-Z0-9_ ] Special or meta characters are used to denote actions or delimit groups:

+ means “one or more of whatever was before the + symbol”

. Matches any single character (i.e., x.z) ^ Matches the starting position within the string $ Matches the ending position of the string or

the position just before a string-ending newline

Page 40: Week Four Agenda

Next lab assignmentPerl Program Statement

#!/usr/bin/perl #!/usr/bin/perl -w

Print continuation statementprint "error: incorrect number of arguments", "\n", "usage: intlist a b (where a < b)", "\n";

Execute Perl scripts:./linenum.pl and ./intlist.pl

Page 41: Week Four Agenda

Break-out problems• $strexp = “This text is considered as a string”;• $intexp = 10;• $floatptexp = 2.54;• $charexp = ‘a’;• $cmdexp = `ls –l`;• $argexp = (“two”, “four”, “six”);• @array_exp = (“Jackie”, “Vicki”, “Alex”);• $array [0] = “new value”;• $a = $b + 5;• $container = @container;• ($map{blue}, $map{orange}, $map{jade}) = (0xff0000, 0x00ff00,

0x0000ff0);

Page 42: Week Four Agenda

Next Lab Assignment

Programming Perl text book reading

Chapter One

Chapter Two

Chapter Three

Page 43: Week Four Agenda

Upcoming deadlines

Lab Assignment 3-1 is due on January 28, 2013.

Lab Assignment 4-1 is due on February 4, 2013.

Lab Assignment 7-1, Midterm exam administered from February 18 through 23.

Midterm outline to be posted on the Bulletin Board by February 3, 2013.

Page 44: Week Four Agenda

Questions and answers

• Questions• Comments• Concerns

• After class, I will help students with their scripts.

Page 45: Week Four Agenda