Page 1 of 1

Cron doesn't execute script

Posted: Thu Oct 31, 2013 12:46 am
by tvick47
Hello Raspbian users!
I have a bit of an issue. I'm trying to automate a script to run at the top of every hour to read the time out loud through speakers connected to my Pi. I wrote a script called time.sh in my home directory, and entered

Code: Select all

* * * * * /home/pi/time.sh
(to test it every minute at first) in my crontab.

However, it does not run successfully! The script itself does run when called manually, and commands entered into crontab run correctly. Under my entry I also entered

Code: Select all

* * * * * date >> /tmp/date.txt
which prints the date every minute to the txt file.

Can anyone give me some insight as to why this isn't working? I've seemingly tried everything... and I'll post the output of my cron log as well as the contents of time.sh if it helps.

Code: Select all

pi@raspberrypi ~ $ grep CRON /var/log/syslog
Oct 30 11:17:01 raspberrypi /USR/SBIN/CRON[6107]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 12:17:01 raspberrypi /USR/SBIN/CRON[6114]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 13:17:01 raspberrypi /USR/SBIN/CRON[6122]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 14:17:01 raspberrypi /USR/SBIN/CRON[6130]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 15:17:01 raspberrypi /USR/SBIN/CRON[6235]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 16:17:01 raspberrypi /USR/SBIN/CRON[6248]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 17:17:01 raspberrypi /USR/SBIN/CRON[6256]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 18:17:01 raspberrypi /USR/SBIN/CRON[6264]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 19:17:01 raspberrypi /USR/SBIN/CRON[6272]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 20:17:01 raspberrypi /USR/SBIN/CRON[6341]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 21:17:01 raspberrypi /USR/SBIN/CRON[6358]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 22:17:01 raspberrypi /USR/SBIN/CRON[6437]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 23:17:01 raspberrypi /USR/SBIN/CRON[6513]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 31 00:17:01 raspberrypi /USR/SBIN/CRON[7491]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 30 20:19:06 raspberrypi /usr/sbin/cron[1936]: (CRON) INFO (pidfile fd = 3)
Oct 30 20:19:06 raspberrypi /usr/sbin/cron[1937]: (CRON) STARTUP (fork ok)
Oct 30 20:19:06 raspberrypi /usr/sbin/cron[1937]: (CRON) INFO (Running @reboot jobs)
Oct 30 20:20:23 raspberrypi /USR/SBIN/CRON[2190]: (root) CMD (/home/pi/time.sh)
Oct 30 20:20:23 raspberrypi /USR/SBIN/CRON[2189]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:21:01 raspberrypi /USR/SBIN/CRON[2211]: (root) CMD (/home/pi/time.sh)
Oct 30 20:21:01 raspberrypi /USR/SBIN/CRON[2210]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:22:01 raspberrypi /USR/SBIN/CRON[2239]: (root) CMD (./home/pi/time.sh)
Oct 30 20:22:01 raspberrypi /USR/SBIN/CRON[2238]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:23:01 raspberrypi /USR/SBIN/CRON[2255]: (root) CMD (/home/pi/time.sh >/dev/null 2>&1)
Oct 30 20:24:01 raspberrypi /USR/SBIN/CRON[2287]: (root) CMD (/home/pi/time.sh >/dev/null 2>&1)
Oct 30 20:25:01 raspberrypi /USR/SBIN/CRON[2299]: (root) CMD (/home/pi/time.sh >/dev/null 2>&1)
Oct 30 20:26:01 raspberrypi /USR/SBIN/CRON[2332]: (root) CMD (/home/pi/time.sh > /tmp/time.log)
Oct 30 20:26:01 raspberrypi /USR/SBIN/CRON[2331]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:27:01 raspberrypi /USR/SBIN/CRON[2344]: (root) CMD (/home/pi/time.sh > /tmp/time.log)
Oct 30 20:27:01 raspberrypi /USR/SBIN/CRON[2343]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:28:01 raspberrypi /USR/SBIN/CRON[2355]: (root) CMD (/home/pi/text2speech.sh "testing cron job")
Oct 30 20:28:04 raspberrypi /USR/SBIN/CRON[2354]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:29:01 raspberrypi /USR/SBIN/CRON[2367]: (root) CMD (/home/pi/text2speech.sh "testing cron job")
Oct 30 20:29:03 raspberrypi /USR/SBIN/CRON[2366]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:30:01 raspberrypi /USR/SBIN/CRON[2397]: (root) CMD (/home/pi/time.sh)
Oct 30 20:30:01 raspberrypi /USR/SBIN/CRON[2396]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:31:01 raspberrypi /USR/SBIN/CRON[2413]: (root) CMD (/home/pi/time.sh)
Oct 30 20:31:01 raspberrypi /USR/SBIN/CRON[2414]: (root) CMD (/home/pi/weather.sh)
Oct 30 20:31:01 raspberrypi /USR/SBIN/CRON[2411]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:31:01 raspberrypi /USR/SBIN/CRON[2412]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:32:01 raspberrypi /USR/SBIN/CRON[2422]: (root) CMD (/home/pi/time.sh)
Oct 30 20:32:01 raspberrypi /USR/SBIN/CRON[2423]: (root) CMD (/home/pi/weather.sh)
Oct 30 20:32:01 raspberrypi /USR/SBIN/CRON[2420]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:32:01 raspberrypi /USR/SBIN/CRON[2421]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:33:01 raspberrypi /USR/SBIN/CRON[2436]: (root) CMD (/home/pi/time.sh)
Oct 30 20:33:01 raspberrypi /USR/SBIN/CRON[2434]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:34:01 raspberrypi /USR/SBIN/CRON[2446]: (root) CMD (/home/pi/time.sh)
Oct 30 20:34:01 raspberrypi /USR/SBIN/CRON[2447]: (root) CMD (date >> /tmp/time.txt)
Oct 30 20:34:01 raspberrypi /USR/SBIN/CRON[2445]: (CRON) info (No MTA installed, discarding output)
Oct 30 20:35:01 raspberrypi /USR/SBIN/CRON[2513]: (root) CMD (/home/pi/time.sh)
and time.sh:

Code: Select all

#!/bin/bash

./text2speech.sh "The current time is $(date +"%H:%M %p")"
Which simply calls the google translation api to download and play the input of date.


Any help would be greatly appreciated! Thanks!

Re: Cron doesn't execute script

Posted: Thu Oct 31, 2013 2:38 am
by scruss
cron has a very limited idea of $PATH, and calling programs with relative paths is unlikely to work as expected.