1

I made a little script that asks Yobit about bitcoin concurrency, and sends some notifications in Ubuntu 17. It works fine if I run the command python coinrates.py. I have made it executable and put #!/usr/bin/python at the top of the file, but it won't work automatically through cron.

I tried:

* * * * * ~/test/yobit/checker.py

and

* * * * * python ~/test/yobit/checker.py

But it doesn't work.

Here is my syslog

Dec  2 12:01:00 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 12:01:00 plombir-N53SV anacron[1303]: Anacron 2.3 started on 2017-12-02
Dec  2 12:01:00 plombir-N53SV anacron[1303]: Normal exit (0 jobs run)
Dec  2 12:17:01 plombir-N53SV CRON[1888]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 13:01:04 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 13:01:04 plombir-N53SV anacron[3601]: Anacron 2.3 started on 2017-12-02
Dec  2 13:01:04 plombir-N53SV anacron[3601]: Normal exit (0 jobs run)
Dec  2 13:17:01 plombir-N53SV CRON[3997]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 14:00:38 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 14:00:38 plombir-N53SV anacron[5171]: Anacron 2.3 started on 2017-12-02
Dec  2 14:00:38 plombir-N53SV anacron[5171]: Normal exit (0 jobs run)
Dec  2 14:17:01 plombir-N53SV CRON[5846]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 15:04:01 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 15:04:01 plombir-N53SV anacron[7072]: Anacron 2.3 started on 2017-12-02
Dec  2 15:04:01 plombir-N53SV anacron[7072]: Normal exit (0 jobs run)
Dec  2 15:17:01 plombir-N53SV CRON[7374]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 16:01:41 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 16:01:41 plombir-N53SV anacron[8489]: Anacron 2.3 started on 2017-12-02
Dec  2 16:01:41 plombir-N53SV anacron[8489]: Normal exit (0 jobs run)
Dec  2 16:17:01 plombir-N53SV CRON[8881]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 17:04:01 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 17:04:01 plombir-N53SV anacron[10177]: Anacron 2.3 started on 2017-12-02
Dec  2 17:04:01 plombir-N53SV anacron[10177]: Normal exit (0 jobs run)
Dec  2 17:17:01 plombir-N53SV CRON[10489]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 18:01:03 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 18:01:03 plombir-N53SV anacron[11610]: Anacron 2.3 started on 2017-12-02
Dec  2 18:01:03 plombir-N53SV anacron[11610]: Normal exit (0 jobs run)
Dec  2 18:17:01 plombir-N53SV CRON[12238]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 19:01:15 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 19:01:15 plombir-N53SV anacron[13850]: Anacron 2.3 started on 2017-12-02
Dec  2 19:01:15 plombir-N53SV anacron[13850]: Normal exit (0 jobs run)
Dec  2 19:10:57 plombir-N53SV crontab[14200]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:11:19 plombir-N53SV crontab[14200]: (plombir) REPLACE (plombir)
Dec  2 19:11:19 plombir-N53SV crontab[14200]: (plombir) END EDIT (plombir)
Dec  2 19:12:01 plombir-N53SV cron[770]: (plombir) RELOAD (crontabs/plombir)
Dec  2 19:17:01 plombir-N53SV CRON[14450]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 19:19:01 plombir-N53SV CRON[14641]: (root) CMD (   test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond)
Dec  2 19:26:45 plombir-N53SV crontab[14932]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:27:00 plombir-N53SV crontab[14932]: (plombir) END EDIT (plombir)
Dec  2 19:27:02 plombir-N53SV crontab[14950]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:28:52 plombir-N53SV crontab[14950]: (plombir) REPLACE (plombir)
Dec  2 19:28:52 plombir-N53SV crontab[14950]: (plombir) END EDIT (plombir)
Dec  2 19:28:59 plombir-N53SV crontab[15043]: (plombir) LIST (plombir)
Dec  2 19:29:01 plombir-N53SV cron[770]: (plombir) RELOAD (crontabs/plombir)
Dec  2 19:45:29 plombir-N53SV crontab[15654]: (plombir) LIST (plombir)
Dec  2 19:56:06 plombir-N53SV crontab[16106]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:56:28 plombir-N53SV crontab[16120]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:56:50 plombir-N53SV crontab[16120]: (plombir) REPLACE (plombir)
Dec  2 19:56:50 plombir-N53SV crontab[16120]: (plombir) END EDIT (plombir)
Dec  2 19:57:01 plombir-N53SV cron[770]: (plombir) RELOAD (crontabs/plombir)
Dec  2 19:59:07 plombir-N53SV crontab[16250]: (plombir) BEGIN EDIT (plombir)
Dec  2 19:59:48 plombir-N53SV crontab[16250]: (plombir) REPLACE (plombir)
Dec  2 19:59:48 plombir-N53SV crontab[16250]: (plombir) END EDIT (plombir)
Dec  2 20:00:01 plombir-N53SV cron[770]: (plombir) RELOAD (crontabs/plombir)
Dec  2 20:00:19 plombir-N53SV crontab[16278]: (plombir) BEGIN EDIT (plombir)
Dec  2 20:04:38 plombir-N53SV systemd[1]: Started Run anacron jobs.
Dec  2 20:04:38 plombir-N53SV anacron[16445]: Anacron 2.3 started on 2017-12-02
Dec  2 20:04:38 plombir-N53SV anacron[16445]: Normal exit (0 jobs run)
Dec  2 20:08:25 plombir-N53SV crontab[16598]: (plombir) LIST (plombir)
Dec  2 20:17:01 plombir-N53SV CRON[16931]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 20:28:20 plombir-N53SV crontab[17378]: (plombir) BEGIN EDIT (plombir)
Dec  2 20:29:11 plombir-N53SV crontab[17378]: (plombir) REPLACE (plombir)
Dec  2 20:29:11 plombir-N53SV crontab[17378]: (plombir) END EDIT (plombir)
Dec  2 20:30:01 plombir-N53SV cron[770]: (plombir) RELOAD (crontabs/plombir)
Dec  2 20:32:19 plombir-N53SV crontab[18553]: (plombir) LIST (plombir)
Dec  2 20:37:00 plombir-N53SV crontab[19748]: (plombir) LIST (plombir)
Dec  2 20:37:17 plombir-N53SV crontab[19765]: (plombir) LIST (plombir)
Zanna
  • 70,465
Yahya
  • 119

1 Answers1

4

You need to use the full path to your python bin file. At the command line type:

whereis python

You should see something along the lines of: /usr/bin/python and perhaps a few others. Use that full path in your cron file, so example:

* * * * * /usr/bin/python ~/test/yobit/checker.py

Then also use the full path to your home directory:

* * * * * /usr/bin/python /home/USERNAME/test/yobit/checker.py
dessert
  • 39,982
kingmilo
  • 10,274
  • I tried, does not work.., I just started to learn Cron, may be I save it wrong? But if I open it again - my code is there, and I tested it echoing some text in the other file, it works well. – Yahya Dec 02 '17 at 17:05
  • Ok, take a look at your syslog file to see what cron is complaining about and paste it here. The log file is located at /var/log/syslog you can use the tail or cat command to view the file, if you need to filter then do so for cron as follows: cat /var/log/syslog |grep cron – kingmilo Dec 02 '17 at 17:11
  • I did, hope it's big enough. It's actually bigger, I just copied a chunk. – Yahya Dec 02 '17 at 17:26
  • You tried editing my answer to paste your update, you should edit your question to paste your updates :) I did see the log file that you pasted though but there was nothing about your cron file. Can you paste the results of cat /var/log/syslog |grep checker and tell me what users crontab you are editing? Is it the root user or is it your own user? – kingmilo Dec 02 '17 at 17:38
  • Sorry, I did what you ask. – Yahya Dec 02 '17 at 17:47
  • Thanks, but now change the command slightly and filter for checker as follows: cat /var/log/syslog |grep checker then paste the results. – kingmilo Dec 02 '17 at 17:56
  • The full path is not the issue with notifications. The issue is that cron has no idea about user's session bus. It is better to not run these types of things as cron jobs, but instead to run them as a background service in the user session. You also really do not want to run as often as is done in the crontab here, as it will almost certainly mean the script constantly keeps getting run over and over again, with no interim timeout. – dobey Dec 02 '17 at 19:35