Goals
In this session you will:
- learn utility: sed
- learn utility: awk
- learn utility: cpio
POST
- log into emperor
- inspect your backup directory
- did your backup run overnight as you expected? If not, why not?
- 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.
- 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
- tweak your backup script to use the tightest compression when using gzip.
- run your backup script manually and see if the new compression settings made any difference. (think ahead for a moment before running it...)
- what does the regular expression
a.p mean?
- what does the regular expression
roa?d mean?
- what does the regular expression
kangaro+ mean?
- what does the regular expression
Oh no* mean?
- what does the regular expression
can(dy|teen) mean?
- what does the regular expression
ca[tn] mean?
- grep /etc/passwd, looking for accounts that contain the string "st".
- how many are there? (hint: use grep)
- grep
/etc/passwd, looking for accounts that don't contain the string "st".
- how many are there?
- grep
/etc/passwd, looking for accounts that start with the string "st".
- grep
/etc/passwd, looking for accounts that start with the string "stnn".
- use the previous step to make a file in your home directory called ""passwd.subset"
- 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.
- 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.
man sed
- sed is a stream editor. It works on one line of input at at time. Upside/downside.
- be prepared for version and vendor differences
- two modes
- command line:
sed 'command' file[s]
- script driven:
sed -f scriptfile file[s]
- The original file is unaffected
- syntax
sed -e 'CriteriaAction'
- if no address is indicated, the processing happens on every line
- address are like:
1,50 lines 1-50
25 line 25
30,$ lines 30-EOF
/cat/, /dog/ lines between the match for cat and dog
- common uses
- substitution
#sub xx with yy on all lines containing TARGET
/TARGET/s/xx/yy/gi
#or just sub xx with yy
s/xx/yy/ #sub first occurrence on the line
s/xx/yy/g #sub all occurrences on teh line
s/xx/yy/4 #sub 4th occurrence
s/xx/yy/gi
- printing a range
#quit on line 11; suppress printing, then print lines specified
sed -n -e '11q;5,10p'
- translation
#translate a to 1, b to 2, etc. on all lines containing TARGET
/TARGET/y/abc/123/g
- deletion
# delete all lines containing TARGET
/TARGET/d
- insertion
#insert text before *line* containing target
/TARGET/i\
some text\
notice the backslash\
before the lines\
except the last one
- appending
#append text after line containing target
/TARGET/a\
some text
goes here
- replacement ("change")
#replace TARGET with lines
/TARGET/c\
some text\
goes here
- list mode
#show non-printable chars
#l as in llama
#usually seen as sed -e 'l'
l
- multiple commands in the same scriptfile
/somelocation/i inserted text
/someotherlocation/i/
more inserted text
- combining multiple commands at the same address
/TARGET/{
someCommand
anotherCommand
}
- reading in from an unrelated file
/TARGET/{
r sourcefile
/TARGET/d
}
- writing out to an unrelated file
/TARGET/w outfile
- famous one-liners
sed G - doublespace a file
sed "G;G" - triplespace a file
sed = filename | sed 'N;s/\n/\t/' - insert line numbers; note \t is tab.
sed 's/^[ \t]*//' - remove leading whitespace
sed 's/[ \t]*$//' - remove trailing whitespace
- sed FAQ
awk
awk is a utility that parses delimited textfiles (like flatfile databases). It, and to a lesser degree sed, have been supplanted by perl.
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.