###前提・実現したいこと
定期的にpythonのプログラムを実行したいです
プログラムの内容は天気予報を喋ってくれるプログラムです
朝9時に知れせてくれる様にしたいです
今は確認&実験の為に2分置きに設定してあります
###該当のソースコード
python
1 2# Edit this file to introduce tasks to be run by cron. 3# 4# Each task to run has to be defined through a single line 5# indicating with different fields when the task will be run 6# and what command to run for the task 7# 8# To define the time you can provide concrete values for 9# minute (m), hour (h), day of month (dom), month (mon), 10# and day of week (dow) or use '*' in these fields (for 'any').# 11# Notice that tasks will be started based on the cron's system 12# daemon's notion of time and timezones. 13# 14# Output of the crontab jobs (including errors) is sent through 15# email to the user the crontab file belongs to (unless redirected). 16# 17# For example, you can run a backup of all your user accounts 18# at 5 a.m every week with: 19# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ 20# 21# For more information see the manual pages of crontab(5) and cron(8) 22# 23# m h dom mon dow command 24 25 26MAILTO="" 27 28#毎時2分にプログラムを実行する 29*/2 * * * * python /home/pi/tenki.py 30
###試したこと
いろんなサイトを見て設定したのですが起動してくれません
更にいろいろ実験(設定)し過ぎたのか?正しく動いているのかすらも怪しい状況です
###補足情報(言語/FW/ツール等のバージョンなど)
今pythonの勉強中でして何か目的を持って勉強するのが良いと考えRaspberry Piで何かできないかなと思い
今に至ります。まだまだ未熟でしてどなたかご教示頂けると幸いです
よろしくお願い致します
**追記**
これまでの流れです
実行したいプログラムの後にログを表示する記述とフルパスになる記述を足しました。
*/2 * * * * python /home/pi/tenki.py 1>> /home/pi/tenki_out.log 2>> /home/pi/tenki_err.log
次に
cat /var/log/syslog | grep CRON を教えて頂き
ログを表示する事が出来ましました
python
1Mar 16 15:10:01 raspberrypi CRON[6690]: (root) MAIL (mailed 548 bytes of output but got status 0x004b from MTA#012) 2Mar 16 15:12:01 raspberrypi CRON[6721]: (root) CMD (python /home/pi/tenki.py) 3Mar 16 15:12:01 raspberrypi CRON[6725]: (pi) CMD (/usr/bin/python /home/pi/tenki.py 1>> /home/pi/tenki_out.log 2>> /home /pi/tenki_err.log) 4Mar 16 15:12:01 raspberrypi CRON[6715]: (root) MAIL (mailed 548 bytes of output but got status 0x004b from MTA#012) 5Mar 16 15:14:01 raspberrypi CRON[6747]: (root) CMD (python /home/pi/tenki.py) 6Mar 16 15:14:01 raspberrypi CRON[6750]: (pi) CMD (/usr/bin/python /home/pi/tenki.py 1>> /home/pi/tenki_out.log 2>> /home /pi/tenki_err.log) 7Mar 16 15:14:01 raspberrypi CRON[6739]: (root) MAIL (mailed 548 bytes of output but got status 0x004b from MTA#012) 8Mar 16 15:16:01 raspberrypi CRON[6773]: (root) CMD (python /home/pi/tenki.py) 9Mar 16 15:16:01 raspberrypi CRON[6776]: (pi) CMD (/usr/bin/python /home/pi/tenki.py 1>> /home/pi/tenki_out.log 2>> /home /pi/tenki_err.log) 10Mar 16 15:16:02 raspberrypi CRON[6766]: (root) MAIL (mailed 548 bytes of output but got status 0x004b from MTA#012) 11 12
↑一部抜粋です
更に
tenki_out.log を確認しました所
jsay 3月16日、15時56分
jsay 3月16日、15時58分
jsay 3月16日、16時0分
jsay 3月16日、16時2分
jsay 3月16日、16時4分
続いて
tenki_err.log を確認しました所
-bash: */2: そのようなファイルやディレクトリはありません
-bash: */2: そのようなファイルやディレクトリはありません
Traceback (most recent call last):
File "/home/pi/tenki.py", line 65, in <module>
main()
File "/home/pi/tenki.py", line 12, in main
say_datetime()
File "/home/pi/tenki.py", line 20, in say_datetime
proc = subprocess.Popen(shlex.split(text))
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
の繰り返しでした
以上が今までの経緯です。
更に追記です(2017/03/21)
前回ご質問させていただき解決したプログラムです
↓
Raspberry piで天気予報を実行したいのですがエラーが出て実行できません。
https://teratail.com/questions/68697
このプログラムを使いcronで定期的にしゃべってもらいたいです
参考にしましたサイト↓
Raspberry Pi | 毎朝、東京の天気予報をしゃべってもらう(お天気Webサービス)
http://www.tapun.net/raspi/raspberry-pi-talk-weather
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/16 05:56
2017/03/16 06:39
2017/03/16 06:57
2017/03/16 08:39
2017/03/16 08:39
2017/03/17 06:27
2017/03/17 08:13
2017/03/21 04:24
2017/03/21 05:45
2017/03/21 06:10
2017/03/21 06:16
2017/03/21 06:22
2017/03/21 06:25
2017/03/21 09:48