-
Notifications
You must be signed in to change notification settings - Fork 2
/
python3_crash_ch11.html
426 lines (358 loc) · 50.7 KB
/
python3_crash_ch11.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="utf-8" />
<title>[雪峰磁针石博客]python3快速入门教程11命令行自动化工具与pexpect</title>
<link rel="stylesheet" href="/theme/css/main.css" />
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="/">python自动化测试人工智能 </a></h1>
<nav><ul>
<li><a href="/category/ba-zi.html">八字</a></li>
<li><a href="/category/ce-shi.html">测试</a></li>
<li><a href="/category/ce-shi-kuang-jia.html">测试框架</a></li>
<li><a href="/category/common.html">common</a></li>
<li><a href="/category/da-shu-ju.html">大数据</a></li>
<li><a href="/category/feng-shui.html">风水</a></li>
<li><a href="/category/ji-qi-xue-xi.html">机器学习</a></li>
<li><a href="/category/jie-meng.html">解梦</a></li>
<li><a href="/category/linux.html">linux</a></li>
<li class="active"><a href="/category/python.html">python</a></li>
<li><a href="/category/shu-ji.html">书籍</a></li>
<li><a href="/category/shu-ju-fen-xi.html">数据分析</a></li>
<li><a href="/category/zhong-cao-yao.html">中草药</a></li>
<li><a href="/category/zhong-yi.html">中医</a></li>
</ul></nav>
</header><!-- /#banner -->
<section id="content" class="body">
<article>
<header>
<h1 class="entry-title">
<a href="/python3_crash_ch11.html" rel="bookmark"
title="Permalink to [雪峰磁针石博客]python3快速入门教程11命令行自动化工具与pexpect">[雪峰磁针石博客]python3快速入门教程11命令行自动化工具与pexpect</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<abbr class="published" title="2018-09-02T13:50:00+08:00">
Published: 日 02 九月 2018
</abbr>
<address class="vcard author">
By <a class="url fn" href="/author/andrew.html">andrew</a>
</address>
<p>In <a href="/category/python.html">python</a>.</p>
</footer><!-- /.post-info --> <h2 id="pexpect">命令行自动化与pexpect</h2>
<h3 id="_1">简介</h3>
<p>Pexpect 是一个用来启动交互式命令行子程序并对其进行自动控制的 Python 工具模块。 Pexpect 可以用来和像 ssh、ftp、passwd、telnet 等命令行程序进行自动交互。可广泛用于自动化运维和测试,实现同时控制多台设备和自动化。Linux中的知名装包软件就使用了Pexpect。 Pexpect在IBM,alibaba,google等公司有广泛使用,在https://pypi.python.org/pypi/pexpect 的日下载量一万左右。</p>
<p>纯python实现,依赖pty模块(不支持Windows)。</p>
<p>最新英文版文档参见:<a href="http://pexpect.readthedocs.org/en/latest/">http://pexpect.readthedocs.org/en/latest/</a></p>
<p>安装:</p>
<p>版本要求:Python 2.6、3.2 或以上</p>
<h3 id="_2">快速入门</h3>
<p>ssh登录是常用的操作,过程如下:</p>
<div class="highlight"><pre><span></span><span class="c1"># ssh [email protected]</span>
<span class="n">test</span><span class="nd">@172.17.100.18</span><span class="s1">'s password: </span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Tue</span> <span class="n">Mar</span> <span class="mi">15</span> <span class="mi">17</span><span class="p">:</span><span class="mi">53</span><span class="p">:</span><span class="mo">01</span> <span class="mi">2016</span> <span class="kn">from</span> <span class="mf">172.17</span><span class="o">.</span><span class="mf">100.19</span>
</pre></div>
<p>下面我们用pexpect来自动实现这个过程:</p>
<div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>
<span class="kn">import</span> <span class="nn">pexpect</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'ssh [email protected]'</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="s1">'password: '</span><span class="p">)</span> <span class="c1"># 等待password:字符出现</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span> <span class="o">+</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span> <span class="c1"># 输出password:前后的字符</span>
<span class="n">child</span><span class="o">.</span><span class="n">sendline</span><span class="p">(</span><span class="s1">'123456'</span><span class="p">)</span> <span class="c1"># 发送密码</span>
<span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="s1">']\$'</span><span class="p">)</span> <span class="c1"># 等待]$字符出现</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span> <span class="o">+</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">interact</span><span class="p">()</span> <span class="c1"># 把ssh的连接交给用户控制。</span>
</pre></div>
<p>上面最后一句在非交互式的情况下要关闭连接,用child.close()替换即可。</p>
<p>上 述操作除了interact外,都可以用python的ssh模块:paramiko代替。不过对于一些同时支持telenet、ftp、ssh等协议命 令行的通信设备,可以用pexpect通杀。telenet、ftp、ssh等从协议的层次联系,pexpect会更接近用户使用,更加适合自动化测试。</p>
<p>两个重要方法: expect()和send() (以及sendline() )。expect可以接受正则表达式作为参数。</p>
<p>before包含预期字符串之前的信息, after包含匹配模式及其以后的内容。</p>
<h3 id="_3"><strong>批量操作多台服务器</strong></h3>
<ul>
<li>
<p>功能:实现同时对多台linux服务器通过ssh执行同一命令。</p>
</li>
<li>
<p>技术基础: python pexpect,不支持windows。</p>
</li>
<li>
<p>参数:</p>
<ul>
<li>
<p>固定参数pwd:远程服务器密码,用户名目前写死是root,可自行修改。</p>
</li>
<li>
<p>可选参数-c CMDS:要执行的命令,比如:"ls -l","cd /home/test && test.py&如果不选择,会从当前目前的cmd.txt读取。</p>
</li>
<li>
<p>可选参数-s SERVERS:目标服务器,比如192.168.0.1,最后一位数可以用-表示一个区间,分号用于分割不同的ip。如果不选择,会从当前目前的ip.txt读取。</p>
</li>
</ul>
</li>
</ul>
<p>库文件:common.py</p>
<div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>
<span class="c1"># Author: Rongzhong Xu</span>
<span class="c1"># CreateDate: 2014-05-06</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">pexpect</span>
<span class="k">class</span> <span class="nc">Ssh</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="n">client</span> <span class="o">=</span> <span class="bp">None</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="s2">"root"</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s2">"123456"</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s1">']#'</span><span class="p">,</span>
<span class="n">silent</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="c1"># Ssh to remote server</span>
<span class="n">ssh_newkey</span> <span class="o">=</span> <span class="s1">'Are you sure you want to continue connecting'</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'ssh '</span> <span class="o">+</span> <span class="n">username</span> <span class="o">+</span> <span class="s1">'@'</span> <span class="o">+</span> <span class="n">ip</span><span class="p">,</span> <span class="n">maxread</span><span class="o">=</span><span class="mi">5000</span><span class="p">)</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
<span class="c1"># Enter password</span>
<span class="k">while</span> <span class="n">i</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">([</span><span class="n">prompt</span><span class="p">,</span> <span class="s1">'assword:*'</span><span class="p">,</span> <span class="n">ssh_newkey</span><span class="p">,</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">TIMEOUT</span><span class="p">,</span>
<span class="s1">'key.*? failed'</span><span class="p">])</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">silent</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="c1"># find prompt</span>
<span class="k">pass</span>
<span class="k">elif</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="c1"># Enter password</span>
<span class="n">child</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">password</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\r</span><span class="s2">"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> <span class="c1"># SSH does not have the public key. Just accept it.</span>
<span class="n">child</span><span class="o">.</span><span class="n">sendline</span><span class="p">(</span><span class="s1">'yes</span><span class="se">\r</span><span class="s1">'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span> <span class="c1"># Timeout</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">'ERROR TIMEOUT! SSH could not login. '</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span> <span class="c1"># new key</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s1">'~'</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'/.ssh/known_hosts'</span><span class="p">)</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span> <span class="o">=</span> <span class="n">child</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">command</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">cmd</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s1">']#'</span><span class="p">,</span> <span class="n">silent</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">buffer</span> <span class="o">=</span> <span class="s1">''</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">cmd</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\r</span><span class="s2">"</span><span class="p">)</span>
<span class="c1"># Ssh.client.setwinsize(400,400)</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">silent</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">after</span>
<span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">cls</span><span class="p">,):</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
<p>主脚本batch.py :</p>
<div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>
<span class="c1"># Author: Rongzhong Xu</span>
<span class="c1"># CreateDate: 2014-05-06</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">common</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">()</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'pwd'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span><span class="n">help</span><span class="o">=</span><span class="sa">u</span><span class="s1">'password'</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-c'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'cmds'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="sa">u</span><span class="s1">'command'</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-s'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'servers'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="sa">u</span><span class="s1">'hosts'</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--version'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'version'</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">'</span><span class="si">%(prog)s</span><span class="s1"> 1.1 Rongzhong xu 2014 05 08'</span><span class="p">)</span>
<span class="n">options</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
<span class="n">servers</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">servers</span><span class="p">:</span>
<span class="n">raw_server</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">servers</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">';'</span><span class="p">)</span> <span class="c1"># ips' decollator is semicolon</span>
<span class="k">for</span> <span class="n">server</span> <span class="ow">in</span> <span class="n">raw_server</span><span class="p">:</span>
<span class="k">if</span> <span class="s1">'-'</span> <span class="ow">in</span> <span class="n">server</span><span class="p">:</span> <span class="c1"># - means continuous ips</span>
<span class="n">server_list</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span>
<span class="n">base</span> <span class="o">=</span> <span class="s1">'.'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">server_list</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
<span class="n">indices</span> <span class="o">=</span> <span class="n">server_list</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'-'</span><span class="p">)</span>
<span class="n">start</span><span class="p">,</span> <span class="n">end</span> <span class="o">=</span> <span class="n">indices</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">start</span><span class="p">),</span><span class="nb">int</span><span class="p">(</span><span class="n">end</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">servers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'{0}.{1}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">base</span><span class="p">,</span><span class="n">item</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">servers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">server</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'ip.txt'</span><span class="p">):</span>
<span class="n">servers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="n">cmds</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">cmds</span><span class="p">:</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">cmds</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'cmd.txt'</span><span class="p">):</span>
<span class="n">servers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="k">for</span> <span class="n">host</span> <span class="ow">in</span> <span class="n">servers</span><span class="p">:</span>
<span class="k">print</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">"*"</span><span class="o">*</span><span class="mi">80</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Connect to host: {0}"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">host</span><span class="p">))</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">common</span><span class="o">.</span><span class="n">Ssh</span><span class="p">()</span>
<span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">host</span><span class="p">,</span><span class="s1">'root'</span><span class="p">,</span><span class="n">options</span><span class="o">.</span><span class="n">pwd</span><span class="p">)</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">cmds</span><span class="p">:</span>
<span class="n">c</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="n">c</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
<p>执行演示:</p>
<div class="highlight"><pre><span></span><span class="c1"># ./batch.py -husage: batch.py [-h] [-c CMDS] [-s SERVERS] [--version] pwdpositional arguments: pwd password</span>
<span class="n">optional</span> <span class="n">arguments</span><span class="p">:</span>
<span class="o">-</span><span class="n">h</span><span class="p">,</span> <span class="o">--</span><span class="n">help</span> <span class="n">show</span> <span class="n">this</span> <span class="n">help</span> <span class="n">message</span> <span class="ow">and</span> <span class="nb">exit</span>
<span class="o">-</span><span class="n">c</span> <span class="n">CMDS</span> <span class="n">command</span>
<span class="o">-</span><span class="n">s</span> <span class="n">SERVERS</span> <span class="n">hosts</span>
<span class="o">--</span><span class="n">version</span> <span class="n">show</span> <span class="n">program</span><span class="s1">'s version number and exit</span>
<span class="c1"># ./batch.py password -s "192.168.0.71-76;123.1.149.26" -c "cat /etc/redhat-release"</span>
<span class="o">********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.71</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">04</span><span class="p">:</span><span class="mo">02</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">183.14</span><span class="o">.</span><span class="mf">8.49</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-release</span>
<span class="n">CentOS</span> <span class="n">release</span> <span class="mf">5.8</span> <span class="p">(</span><span class="n">Final</span><span class="p">)</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1">#</span>
<span class="o">********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.72</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">03</span><span class="p">:</span><span class="mo">05</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.232</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-release</span>
<span class="n">CentOS</span> <span class="n">release</span> <span class="mf">5.8</span> <span class="p">(</span><span class="n">Final</span><span class="p">)</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1">#</span>
<span class="o">********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.73</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">02</span><span class="p">:</span><span class="mi">29</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.232</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-release</span>
<span class="n">CentOS</span> <span class="n">release</span> <span class="mf">5.8</span> <span class="p">(</span><span class="n">Final</span><span class="p">)</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1">#</span>
<span class="o">********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.74</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">02</span><span class="p">:</span><span class="mi">32</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.232</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-release</span>
<span class="n">CentOS</span> <span class="n">release</span> <span class="mf">5.8</span> <span class="p">(</span><span class="n">Final</span><span class="p">)</span>
<span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1">#</span>
<span class="o">********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.75</span>
<span class="n">root</span><span class="nd">@192.168.0.75</span><span class="s1">'s p assword: </span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">02</span><span class="p">:</span><span class="mi">56</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.232</span><span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-releaseCentOS release 6.4 (Final)[root@localhost ~ ]#********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.76</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">17</span><span class="p">:</span><span class="mo">03</span><span class="p">:</span><span class="mo">00</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">192.168</span><span class="o">.</span><span class="mf">0.232</span><span class="p">[</span><span class="n">root</span><span class="nd">@localhost</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-releaseCentOS release 5.8 (Final)[root@localhost ~ ]#********************************************************************************</span>
<span class="n">Connect</span> <span class="n">to</span> <span class="n">host</span><span class="p">:</span> <span class="mf">123.1</span><span class="o">.</span><span class="mf">149.26</span>
<span class="n">Last</span> <span class="n">login</span><span class="p">:</span> <span class="n">Thu</span> <span class="n">May</span> <span class="mi">8</span> <span class="mi">16</span><span class="p">:</span><span class="mi">46</span><span class="p">:</span><span class="mi">56</span> <span class="mi">2014</span> <span class="kn">from</span> <span class="mf">183.56</span><span class="o">.</span><span class="mf">157.199</span><span class="p">[</span><span class="n">root</span><span class="nd">@LINUX</span> <span class="o">~</span> <span class="p">]</span><span class="c1"># cat /etc/redhat-releaseRed Hat Enterprise Linux Server release 6.5 (Santiago)[root@LINUX ~ ]#[root@AutoTest batch]#</span>
</pre></div>
<h3 id="_4"><strong>其他命令自动化工具</strong></h3>
<p><a href="https://pypi.python.org/pypi/Fabric/">https://pypi.python.org/pypi/Fabric/</a> python远程执行与部署库,运维的最爱。</p>
<p><a href="https://fedorahosted.org/func/">https://fedorahosted.org/func/</a></p>
<p><a href="https://pypi.python.org/pypi/pyserial/">https://pypi.python.org/pypi/pyserial/</a></p>
<p><a href="https://pypi.python.org/pypi/paramiko/1.16.0">https://pypi.python.org/pypi/paramiko/1.16.0</a></p>
<p><a href="https://docs.python.org/2/library/subprocess.html">https://docs.python.org/2/library/subprocess.html</a></p>
<p><a href="https://pypi.python.org/pypi/sh">https://pypi.python.org/pypi/sh</a></p>
<h3 id="api">API概览</h3>
<h4 id="eoftimeout">EOF与TIMEOUT</h4>
<p>EOF(End Of File)与TIMEOUT可以在expect方法中使用,它们不是正则表达式,而是常量。</p>
<p>源于异常,而不是BaseException例外。从BaseException直接继承的例外情况赶上他们几乎总是错误的做法保留。 </p>
<p>如果子进程已经退出,读取子进程的输出会引发EOF异常。此时子进程的输出全部在before中。 </p>
<p>expect()接受的参数是正则表达式或正则表达式列表,可匹配多个可选的响应。比如ssh登录的各种情况处理:</p>
<div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Ssh</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="n">client</span> <span class="o">=</span> <span class="bp">None</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="s2">"root"</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s2">"123456"</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s1">']#'</span><span class="p">,</span>
<span class="n">silent</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="c1"># Ssh to remote server</span>
<span class="n">ssh_newkey</span> <span class="o">=</span> <span class="s1">'Are you sure you want to continue connecting'</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'ssh '</span> <span class="o">+</span> <span class="n">username</span> <span class="o">+</span> <span class="s1">'@'</span> <span class="o">+</span> <span class="n">ip</span><span class="p">,</span> <span class="n">maxread</span><span class="o">=</span><span class="mi">5000</span><span class="p">)</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
<span class="c1"># Enter password</span>
<span class="k">while</span> <span class="n">i</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">([</span><span class="n">prompt</span><span class="p">,</span> <span class="s1">'assword:*'</span><span class="p">,</span> <span class="n">ssh_newkey</span><span class="p">,</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">TIMEOUT</span><span class="p">,</span>
<span class="s1">'key.*? failed'</span><span class="p">])</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">silent</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span> <span class="o">+</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="c1"># find prompt</span>
<span class="k">pass</span>
<span class="k">elif</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="c1"># Enter password</span>
<span class="n">child</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">password</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\r</span><span class="s2">"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> <span class="c1"># SSH does not have the public key. Just accept it.</span>
<span class="n">child</span><span class="o">.</span><span class="n">sendline</span><span class="p">(</span><span class="s1">'yes</span><span class="se">\r</span><span class="s1">'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span> <span class="c1"># Timeout</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">'ERROR TIMEOUT! SSH could not login. '</span><span class="p">)</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span> <span class="c1"># new key</span>
<span class="k">print</span><span class="p">(</span><span class="n">child</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">child</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s1">'~'</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'/.ssh/known_hosts'</span><span class="p">)</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span> <span class="o">=</span> <span class="n">child</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">command</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">cmd</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s1">']#'</span><span class="p">,</span> <span class="n">silent</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">buffer</span> <span class="o">=</span> <span class="s1">''</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">cmd</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\r</span><span class="s2">"</span><span class="p">)</span>
<span class="c1"># Ssh.client.setwinsize(400,400)</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">silent</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">before</span> <span class="o">+</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">after</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">before</span><span class="p">,</span> <span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">after</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">cls</span><span class="p">,):</span>
<span class="n">Ssh</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
<p>expect()的超时默认为30秒,超时时生成TIMEOUT异常。可以修改:</p>
<div class="highlight"><pre><span></span><span class="c1"># Wait no more than 2 minutes (120 seconds) for password prompt.</span>
<span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="s1">'password:'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">120</span><span class="p">)</span>
</pre></div>
<h4 id="_5">行尾处理</h4>
<p>Pexpect匹配的正则表达式与标准的有些差异,默认是非贪婪匹配。Pexpect一次读取一个字符读,这样行尾标识$失去了意义。行尾用"\r\n"(CR/LF)表示。Pexpect中的"\n"实际对应"\r\n"。匹配行尾的操作如下:</p>
<div class="highlight"><pre><span></span><span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">'</span><span class="p">)</span>
</pre></div>
<p>尽量用:</p>
<div class="highlight"><pre><span></span><span class="n">child</span><span class="o">.</span><span class="n">expect</span> <span class="p">(</span><span class="s1">'.+'</span><span class="p">)</span>
</pre></div>
<p>而不是:</p>
<div class="highlight"><pre><span></span><span class="n">child</span><span class="o">.</span><span class="n">expect</span> <span class="p">(</span><span class="s1">'.*'</span><span class="p">)</span>
</pre></div>
<h3 id="api_1">API文档</h3>
<p>pexpect.screen和pexpect.ANSI在版本4已经不推荐使用,建议用pyte替代。</p>
<h4 id="class-spawn">class spawn</h4>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[],</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">maxread</span><span class="o">=</span><span class="mi">2000</span><span class="p">,</span>
<span class="n">searchwindowsize</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">logfile</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cwd</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">env</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
<span class="n">ignore_sighup</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
</pre></div>
<p>调用示例:</p>
<div class="highlight"><pre><span></span><span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'/usr/bin/ftp'</span><span class="p">)</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'/usr/bin/ssh [email protected]'</span><span class="p">)</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'ls -latr /tmp'</span><span class="p">)</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'/usr/bin/ftp'</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'/usr/bin/ssh'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'[email protected]'</span><span class="p">])</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'ls'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'-latr'</span><span class="p">,</span> <span class="s1">'/tmp'</span><span class="p">])</span>
</pre></div>
<p>pexpect不能解释shell元字符,比如 (>, |, or *),需要启动shell来解决该问题:</p>
<div class="highlight"><pre><span></span><span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'/bin/bash -c "ls -l | grep LOG > logs.txt"'</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">expect</span><span class="p">(</span><span class="n">pexpect</span><span class="o">.</span><span class="n">EOF</span><span class="p">)</span>
</pre></div>
<p>日志输出:</p>
<div class="highlight"><pre><span></span><span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'some_command'</span><span class="p">)</span>
<span class="n">fout</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'mylog.txt'</span><span class="p">,</span><span class="s1">'wb'</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">logfile</span> <span class="o">=</span> <span class="n">fout</span>
</pre></div>
<p>输出到stdout</p>
<div class="highlight"><pre><span></span><span class="c1"># In Python 2:</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s1">'some_command'</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">logfile</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="c1"># </span>
<span class="n">In</span> <span class="n">Python</span> <span class="mi">3</span><span class="p">,</span> <span class="n">spawnu</span> <span class="n">should</span> <span class="n">be</span> <span class="n">used</span> <span class="n">to</span> <span class="n">give</span> <span class="nb">str</span> <span class="n">to</span> <span class="n">stdout</span><span class="p">:</span>
<span class="n">child</span> <span class="o">=</span> <span class="n">pexpect</span><span class="o">.</span><span class="n">spawnu</span><span class="p">(</span><span class="s1">'some_command'</span><span class="p">)</span>
<span class="n">child</span><span class="o">.</span><span class="n">logfile</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span>
</pre></div>
<h2 id="_6">参考资料</h2>
<ul>
<li>python测试等IT技术支持qq群: 144081101(后期会录制视频存在该群群文件) 591302926 567351477 钉钉免费群:21745728</li>
<li>道家技术-手相手诊看相中医等钉钉群21734177 qq群:391441566 184175668 338228106 看手相、面相、舌相、抽签、体质识别。服务费50元每人次起。请联系钉钉或者微信pythontesting</li>
<li><a href="https://china-testing.github.io/python3_crash_ch11.html">本文最新版本地址</a></li>
<li><a href="https://github.com/china-testing/python-api-tesing">本文涉及的python测试开发库</a> 谢谢点赞!</li>
<li><a href="https://github.com/china-testing/python-api-tesing/blob/master/books.md">本文相关海量书籍下载</a></li>
<li><a href="https://china-testing.github.io/testing_training.html">接口自动化性能测试线上培训大纲</a></li>
</ul>
</div><!-- /.entry-content -->
</article>
</section>
<section id="extras" class="body">
<div class="blogroll">
<h2>links</h2>
<ul>
<li><a href="https://china-testing.github.io/testing_training.html">自动化性能接口测试线上及深圳培训与项目实战 qq群:144081101 591302926</a></li>
<li><a href="http://blog.sciencenet.cn/blog-2604609-1112306.html">pandas数据分析scrapy爬虫 521070358 Py人工智能pandas-opencv 6089740</a></li>
<li><a href="http://blog.sciencenet.cn/blog-2604609-1112306.html">中医解梦看相八字算命qq群 391441566 csdn书籍下载-python爬虫 437355848</a></li>
</ul>
</div><!-- /.blogroll -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<address id="about" class="vcard body">
Proudly powered by <a href="http://getpelican.com/">Pelican</a>, which takes great advantage of <a href="http://python.org">Python</a>.
</address><!-- /#about -->
<p>The theme is by <a href="http://coding.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/">Smashing Magazine</a>, thanks!</p>
</footer><!-- /#contentinfo -->
</body>
</html>