“蟒蛇脚本”中的Cron工作:中途停止

时间:2012-12-03 09:42:42

标签: python cron

我正在尝试cronjob我的python脚本。我通过cPanel设置它,我的python脚本生成一个像它应该的html文件,所以我知道它正确的命令(只是“python / path”对吗?)

但是,我生成的html停止了一半(在第二个f.write()之后,我的for循环应该开始)。

当我在本地执行此脚本时,我没有遇到任何问题,是什么给出了?

from SearchPhone import SearchPhone

phones = ["Iphone 3", "Iphone 4", "Iphone 5","Galaxy s3", "Galaxy s2", "LG Lucid", "LG Esteem", "HTC One S", "Droid 4",
          "Droid RAZR MAXX", "HTC EVO", "Galaxy Nexus", "LG Optimus 2", "LG Ignite",
          "Galaxy Note", "HTC Amaze", "HTC Rezound", "HTC Vivid", "HTC Rhyme", "Motorola Photon",
          "Motorola Milestone", "myTouch slide", "HTC Status", "Droid 3", "HTC Evo 3d", "HTC Wildfire",
          "LG Optimus 3d", "HTC ThunderBolt", "Incredible 2", "Kyocera Echo", "Galaxy S 4g",
          "HTC Inspire", "LG Optimus 2x", "Samsung Gem", "HTC Evo Shift", "Nexus S", "LG Axis", "Droid 2",
          "G2", "Droid x", "Droid Incredible" 
          ]

f = open('celly.html','w')


f.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Celly Blue Book</title>
</head>

<body>
</body>
</html>
""")

#table
f.write('<table width="100%" border="1">')
for x in phones:
    y = SearchPhone(x)
    f.write( "\t<tr>")
    f.write( "\t\t<td>" + str(y[0]) + "</td>")
    f.write( "\t\t<td>" + str(y[1]) + "</td>")
    f.write( "\t\t<td>" + str(y[2]) + "</td>")
    f.write( "\t\t<td>" + str(y[3]) + "</td>")
    f.write( "\t\t<td>" + str(y[4]) + "</td>")
    f.write( "\t</tr>"

f.write('</table>')

f.close()

1 个答案:

答案 0 :(得分:1)

  1. for循环中的最后一行有语法错误:

    f.write( "\t</tr>"

  2. 您可能没有生产服务器的写入权限。 试一试。

  3. f = open('/tmp/celly.html','w')

    如果这样,那么它就是写权限问题。 检查你的权限 当前文件夹中的celly.html文件。它应该是可写的。