【发布时间】:2018-11-08 18:02:11
【问题描述】:
我正在尝试在系统启动时启动 SimpleHTTPServer。我正在使用基于 Linux 的 Raspbian OS。为此,我在 crontab 文件中添加了以下行:
@reboot serverfile.sh
现在在 serverfile.sh 中,我放了以下内容:
#!/bin/bash
python -m SimpleHTTPServer
已赋予文件执行权限,修改后可打印echo命令。但是服务器不会在引导时启动。 同样的命令,
python -m SimpleHTTPServer
在终端中运行时工作正常。 我在这里做错了什么?
以下是我的 CRON 日志
pi@raspberrypi:~ $ grep CRON /var/log/syslog
Oct 16 07:17:01 raspberrypi CRON[17192]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 08:17:01 raspberrypi CRON[17230]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 09:17:01 raspberrypi CRON[17265]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 10:17:01 raspberrypi CRON[17301]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 10:17:03 raspberrypi cron[319]: (CRON) INFO (pidfile fd = 3)
Oct 16 10:17:03 raspberrypi cron[319]: (CRON) INFO (Running @reboot jobs)
Oct 16 10:17:03 raspberrypi cron[298]: (CRON) INFO (pidfile fd = 3)
Oct 16 10:17:03 raspberrypi cron[298]: (CRON) INFO (Running @reboot jobs)
Oct 16 11:17:01 raspberrypi CRON[1718]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 11:51:38 raspberrypi cron[276]: (CRON) INFO (pidfile fd = 3)
Oct 16 11:51:38 raspberrypi cron[276]: (CRON) INFO (Running @reboot jobs)
Oct 16 12:17:01 raspberrypi CRON[1019]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 13:17:02 raspberrypi CRON[1051]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 14:17:01 raspberrypi CRON[1171]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 16 15:17:01 raspberrypi CRON[1283]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Binary file /var/log/syslog matches
【问题讨论】:
-
你检查过你的 cron 日志吗?
-
没有。让我一会儿回来。
-
使用 Python 的完整路径:
which python -
这是python 2.7。但它确实适用于有一些其他内容的
python myfile.py -
这篇文章可能会有所帮助:unix.stackexchange.com/questions/109804/…
标签: python shell raspbian simplehttpserver