squeak!
Syllabus Homepage
Course Overview
Course resources
Day 1
Day 2
Day 3
Day 4
Common errors
Internet Glossary
About Your Instructor
Credits: This site powered by the vi text editor, apache webserver, perl scripting, and Debian linux.
squeak!

unix intermediate - Day 3

Goals

In this session you will:
  • learn utility: sed
  • learn utility: awk
  • learn utility: cpio

POST

  1. log into emperor
  2. inspect your backup directory
  3. did your backup run overnight as you expected? If not, why not?
  4. look at your email. Are you receiving messages from cron that you might or might not expect? If they're not what you expected, think about what might be necessary to correct them.
  5. edit your cron table, making any necessary changes. If no changes are necessary, ensure your cron table is commented and uses verbose flags where needed for clarity
  6. tweak your backup script to use the tightest compression when using gzip.
  7. run your backup script manually and see if the new compression settings made any difference. (think ahead for a moment before running it...)
  8. what does the regular expression a.p mean?
  9. what does the regular expression roa?d mean?
  10. what does the regular expression kangaro+ mean?
  11. what does the regular expression Oh no* mean?
  12. what does the regular expression can(dy|teen) mean?
  13. what does the regular expression ca[tn] mean?
  14. grep /etc/passwd, looking for accounts that contain the string "st".
  15. how many are there? (hint: use grep)
  16. grep /etc/passwd, looking for accounts that don't contain the string "st".
  17. how many are there?
  18. grep /etc/passwd, looking for accounts that start with the string "st".
  19. grep /etc/passwd, looking for accounts that start with the string "stnn".
  20. use the previous step to make a file in your home directory called ""passwd.subset"
  21. inspect the login file(s) for your shell. Ensure that your EDITOR and VISUAL environmental vars are set. What else is happening in that/those files.
  22. inspect the .appnamerc file for your shell. How is this file different from the login file in the previous step? What is happening in this file?

sed

sed is a Stream (non-interactive) Editor. Your familiarity with vi will help get you up to speed on sed, as vi was partially based on sed.

awk

awk is a utility that parses delimited textfiles (like flatfile databases). It, and to a lesser degree sed, have been supplanted by perl.
  • man awk
  • be prepared for version and vendor differences
  • command line: awk 'command' file[s]
  • script driven: awk -f scriptfile file[s]
    notice similarity to sed syntax
  • Fields
    • delimited: FS=":" or -F:. Default seperator is a space, :, | and \t are common.
    • $0 is the entire line, $1 is first field, $2 is second field, etc.
    • NR is the current line number
    • NF number of fields/words
    • {print NR, $1, $3}
    • advanced: fixed-length and multiline records
  • Criteria
    • /foo/ work on those lines that contain foo, printing by default
    • && and
    • || or
    • ! negation
    • common uses
      • grep-like searching
        	#print out all lines in infile that contain bash
        	#$0 == the current line
        	'/bash/ {print $0}'  #printing the line is the default
        	
      • printing out a given field
        	awk -f myAwkScript /etc/passwd
        
        	#setting the field seperator
        	FS=":"
        	#print the fourth field from each line that contains TARGET
        	/TARGET/ {print $1		$4}
        	
    • finding text in a field
      	awk -f myAwkScript /etc/passwd
      	#setting the field seperator
      	FS=":"
      	#print the fourth field if it contains bash
      	/bash/ {print $7}
      	
    • NF = number of fields in current record
    • NR = number of the current record (usually line number)

    
    #variables declared in begin statement
    BEGIN { print FILENAME; p = 0 }
    /From / && / 199/           { p = 0 }
    /From / && /cc.adfa.oz.au/  { p = 1 }
    { if (p > 0) print "Here it is: ", $0 }
    END   { print "End ..." }
    
    
    

teaser: expect

teaser: perl

teaser: gcc/make

using cpio for incremental backups

  • use find or a file list to ID what gets backed up
  • make an archive: cpio -o > archive.cpio
  • unpack an archive: cpio -imd 'pattern' < archive.cpio

Conclusion

Where to go from here

  • other coursework
  • outside work


http://www.mousetrap.net/syllabus/interunix/day3.html
$Id: day3.orb,v 1.16 2003/02/07 14:00:48 mouse Exp $

Remember, your login is based on your machine's hostname, not on any other number.
~/[initials] refers to the subdirectory under your homedir, named after your initials. Everything except for .dotfiles will be stored in your ~/[initials] directory.


© 1995-2001 jason carr
Distributed under the terms of the GNU Free Documentation License.