Errata

Python for Unix and Linux System Administration

Errata for Python for Unix and Linux System Administration

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
sec. 5.5
4th capture


In the line:
>>> ans,unans=sr(IP(dst="oreilly.com", ttl=(4,25),id=RandShort())/TCP(flags=0x2))

all the stimuli and answers will look alike. Thus Scapy may mismatch an answer with the wrong stimulus. To avoid this, you can set TCP source port to a random value: TCP(sport=RandShort())
IPID being random does not help.

Philippe Biondi
 
Nov 18, 2008 
Sec. 5.5
4th capture

The capture says:
---
>>> ans,unans=sr(IP(dst="oreilly.com",
>>> ttl=(4,25),id=RandShort())/TCP(flags=0x2))
Begin emission:
..............*Finished to send 22 packets.
*...........*********.***.***.*.*.*.*.*
Received 54 packets, got 22 answers, remaining 0 packets
>>> for snd, rcv in ans:
... print snd.ttl, rcv.src, isinstance(rcv.payload, TCP)
...
[snip]
20 208.201.239.37 True
21 208.201.239.37 True
22 208.201.239.37 True
23 208.201.239.37 True
24 208.201.239.37 True
25 208.201.239.37 True
---

* the first line has been cut in 2 and ">>>" has been wrongly added
* showing some lines before hop 20 could be more didactic
* flags="S" is also possible and more human readable than 0x2

Philippe Biondi
 
Nov 18, 2008 
Sec 3.3
second capture, between Exemple 3-27 and 3-28

It seems like the capture has been truncated and is missing a <array> opening tag at the begining and </dict></array> tags at the end.

Philippe Biondi
 
Nov 18, 2008 
sec. 5.5
Before but-last capture

imagemagick is misspelled as imagemagic

Philippe Biondi
 
Nov 18, 2008 
5.15
Chapter 5, Section 5.1.5

"Another high level library is urllib2. Urllib2 contains pretty... "

should be:

"Another high level library is urllib2. urllib2 contains pretty... "

These capitalization errors apparently occur in other areas of the book as well.

Thanks to nsheridan for pointing this out in our book forum.

Anonymous  Jan 15, 2009 
9
2nd code snippet

The line:
In [ 3] : subprocess.call(["ls","-l ","/tmp/"])
should be:
In [ 3] : subprocess.call(["ls","-l","/tmp/"])

the extra space after -l returns with an invalid option and an error value of 2.

Aria Kraft  Jul 30, 2010 
Printed Page 9
5th line from the bottom

if you ran ls -ls from the command line:

should be

if you ran ls -l from the command line:

Kyungwon Chun  Oct 04, 2010 
9
Page 9, line 8

There should be no space after "-l" in line "subprocess.call(["ls","-l ","/tmp/"])".

Anonymous  Jun 20, 2012 
PDF Page 43
Paragraph "Variable Expansion"

The example expands variable i resulting in echoing the positional parameters of the shell to be substituted instead of numbers, i.e., the output yields:
/bin/sh.txt
.txt
.txt
...

instead of 0.txt, 1.txt and so on.

Anonymous  Nov 03, 2015 
Printed Page 63
5th line from top (including empty line)

The "demonstrations/examples" don't work.

------My Result 1 -------
In [1]: !!ls apa*py
ls: cannot access apa*py: No such file or directory
Out[1]: SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0:

In [2]:
------- End My Result 1 ----------

The second example doesn't work either
------My Result 2 -------
In [2]: !!ls e*py
ls: cannot access e*py: No such file or directory
Out[2]: SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0:
------- End My Result 2 --------

The third example doesn't work either
-------- My Result 3 --------
In [3]: !!ls t*py
ls: cannot access t*py: No such file or directory
Out[3]: SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
0:

---------
---------
Python 2.5.2 (r252:60911, Sep 30 2008, 15:42:03)
IPython 0.8.4

Anonymous  Jun 12, 2009 
Printed Page 141
pp 141-142, examples 4-5 and 4-6

The examples of how to set up the to, from, and subject headers for sending an email message via smtp are both (a) clumsy and hard to make sense of, and (b) incorrect.

Something like this solves both of those problems:
<pre>

email_message = "".join(
[ "From: " , from_address , "\r\n"
, "To: " , to_address , "\r\n"
, "Subject: ", subject , "\r\n"
, "\r\n" # an extra newline between the headers and message body
, message
])

</pre>

Anonymous  Jan 16, 2009 
Printed Page 158
4th paragraph

The text says "Another high level library is urllib2. Urllib2 contains ..."

In python the case of words matters so urllib2 and Urllib2 are two different things. It may look weird but using the proper case for Python libraries even when they start a sentence would be more technically correct. For someone new to Python this could be confusing.

This is actually just one example of this happening in the book.

Eric Lake  Feb 13, 2009 
Other Digital Version 161
Location 2469

More instances of inappropriate capitalisation

Please the other instances of capitalisation at the start of sentences resulting incorrect names. Within a single sentence the string method join() is written as both Join() and join().

"Join() is a string method so calling join() on a ... Join() takes a sequence of strings ..."

Michael Mayer  Dec 30, 2011 
PDF Page 193
Example 6-11

from diskwalk_api import diskwalk
In [2]: files = diskwalk("/tmp")
In [3]: from fnmatch import fnmatch
In [4]: for file in files:
...: if fnmatch(file,"*.txt"):
...: print file


should be files = diskwalk("/tmp").enumeratePaths(), diskwalk is not an iterable object

On page 189, Example 6-8

missing from os.path import getsize
in ipython session before invoking getsize



Anonymous  Oct 09, 2008 
Printed Page 290
2nd paragraph

"it is often desirable to suprocess the stdout" should be "it is often desirable to suppress the stdout"

Duncan Hutty  Dec 13, 2010 
Printed Page 294
Example 10-9

Example 10-9 does not use the args.pop construct as cited in the text:

"Due to the power of python and *args, we can arbitrarily run commands using our function as a factory. Each command gets popped off a list starting at the beginning due to the args.pop(0) syntax."

but is instead a duplication of the subsequent example using the for loop construct.

Ash Macon  Mar 09, 2011 
PDF Page 295
Code Snippet

Indentation is incorrect for module subtube. However, it is correct in the python code files provided with the book. Correct indentation is as follows. In the PDF version both def run (self): methods and class Runner(BaseArgs): are incorrectly indented.

#!/usr/bin/env python
from subprocess import call
import time
import sys

"""Subtube is module that simplifies and automates some aspects of subprocess"""

class BaseArgs(object):
"""Base Argument Class that handles keyword argument parsing"""

def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
if self.kwargs.has_key("delay"):
self.delay = self.kwargs["delay"]
else:
self.delay = 0
if self.kwargs.has_key("verbose"):
self.verbose = self.kwargs["verbose"]
else:
self.verbose = False

def run (self):
"""You must implement a run method"""
raise NotImplementedError

class Runner(BaseArgs):
"""Simplifies subprocess call and runs call over a sequence of commands

Runner takes N positional arguments, and optionally:

[optional keyword parameters]
delay=1, for time delay in seconds
verbose=True for verbose output

Usage:

cmd = Runner("ls -l", "df -h", verbose=True, delay=3)
cmd.run()

"""
def run(self):
for cmd in self.args:
if self.verbose:
print "Running %s with delay=%s" % (cmd, self.delay)
time.sleep(self.delay)
call(cmd, shell=True)

Gourav Shah  Jun 13, 2009 
Printed Page 331
example 11-3

The example code contains an incorrect sequence of calls.
The curses.wrapper call instantiates a screen, thus the curses.initscr call in __init__ is unnecessary. Due to these problems the screen is not reset on exiting the application.

A way the problem gets solved is as follows: (note this is a file_viewer instead of a log_viewer)


#!/usr/local/bin/python3.0
'file_viewer.py - uses curses to scroll thru a file'

import curses
import sys

class Viewer(object):

def page_up(self):
self.curr_topline = self.curr_topline - (2 * curses.LINES)
if self.curr_topline < 0:
self.curr_topline = 0
self.draw_lines()

def page_down(self):
self.draw_lines()

def load_lines(self):
fd = open(self.file, 'rb')
for line_no, line in enumerate(fd):
self.lines.append(str(line_no) + str(line))
fd.close()
self.draw_lines()

def draw_lines(self):
self.screen.clear()
for y in range(curses.LINES):
try:
line = self.lines[self.curr_topline]
except IndexError:
break
self.screen.addstr(y, 0, str(line) )
self.curr_topline += 1
self.screen.refresh()

def main_loop(self, stdscr, file=None):
self.screen = stdscr # as initialised by curses.wrapper
self.curr_topline = 0
self.file = file
self.lines = []
self.load_lines()
while True:
c = self.screen.getch()
try:
c = chr(c)
except ValeError:
continue
if c == 'd':
self.page_down()
elif c == 'u':
self.page_up()
elif c == 'q':
break

if __name__ == "__main__":
file = sys.argv[1]
curses.wrapper(Viewer().main_loop, file)

The sample code also contains:
- redundant screen.clear calls
- redundant initialisation of self.loglines

Nick de Bray  Jan 11, 2009 
Other Digital Version 350
Last paragraph

Incorrect reference to succeeding chapter.

The last paragraph of this section (Chapter 7 - Ipthon and Net-SNMP )starts thus "Fortunately, as you found out in the processes and concurrency chapter ...". Unfortunately the processes and concurrency chapter is chapter 10 in the published book.

The text should read something like this
"Fortunately, as you will find out in the processes and concurrency chapter ..."

Anonymous  Dec 30, 2011 
Printed Page 368
First paragraph

It looks like the author meant for part of the first sentence be shown as code output but is not formatted that way in the book as it is for content much like it on the previous page.

The part that should be formatted as code output is:


jmjones@kinkgutsy:~/code$ cat nonblock.yaml
bam:[1,2,3]
bar:b
foo:a

etank  Feb 27, 2009 
Printed Page 388
4th example output arrow

./sysargv.py foo

should return

['./sysargv.py', 'foo']

and not

['./sysargv.py', 'test'] as printed.

Karl J. Smith  Apr 15, 2009 
Printed Page 390
1st paragraph under example output

The example uses the option '--infinity'.

The paragraph's last sentence says "......entered an option, readability, that did not exist for Perl."

Two problems:

1) the option is 'infinity', not 'readability'
2) This is a book on Python, not Perl.

Karl J. Smith  Apr 15, 2009 
PDF, Other Digital Version Page 403
First paragraph

The last sentence of the paragraph refers to detailed coverage of the ConfigParser library. There is no coverage of ConfigParser in Chapter 12. ConfigParser is used within Example 8-7 (Chapter 8. page 234).

I guess that an earlier draft of the book contained a sub-section on ConfigParser which was cut for reasons of length.

Michael Mayer  Jan 08, 2012 
PDF, Other Digital Version Page 403
Example 13-13

This example completely ignores the advice given by the authors in the tip just above of not relying on the location of elements within a configuration file. The example uses an absolute fixed location to populate the variable phrase.

The examples should follow the best practice identified by the authors not just a quick and easy implementation.

Michael Mayer  Jan 08, 2012 
Other Digital Version 5033
3rd paragraph, first sentence, last word.

Location 5033. Near example 5-9

The python library is called "paramiko", but spelled "paramkio"

James Downs  Apr 08, 2012