8

I am new to using crontab, and I've been trying to get a simple cron job working. The code for the cron job is as follows:

 */1 * * * * echo "job every minute"

So just for proof-of-concept, I want to see this printed every minute. I have tried saving this cron job using both

 sudo crontab -e

and by saving a crontab file (cronscript) in a directory and enabling the script as follows:

 crontab ~/Documents/MyProjects/cronscript

which is the path for where the cron job is located. Both of the identical jobs are saved properly, as I have verified by typing

  sudo crontab -e

and crontab -e

into terminal and they both appear. I made sure there was a new line character saved after each command, and I checked to make sure cron is running by using

 pgrep cron

However, I am still not getting "job every minute" printed to terminal (every minute) which is what I believe these commands should be doing.

What am I doing wrong? Thanks for the help!

MEric
  • 946
  • 3
  • 12
  • 30

1 Answers1

8

The cronjob is running just fine, but the cron daemon (daemons in general as far as I know) have no access to stdout so cannot output messages to the terminal.

To test it you can, however, output what you want to a file using

*/1 * * * * echo "job every minute" >>$HOME/filename

which will output (and concatenate) the text to a file named "filename" in your home directory every minute.

Ken Herbert
  • 5,205
  • 5
  • 28
  • 37
  • I tried this fix, and it is not saving the output to my home directory. – MEric Jul 04 '13 at 06:06
  • Actually, I updated it in the crontab -e and it worked! Now I'm trying to run a python script (crontest.py) defined as follows: #!/usr/bin/env python print("test") The script is saved in my home directory, and I have modified my cronjob to the following: */1 * * * * $HOME/crontest.py However, it is not printing anything to the console. Any suggestions? Sorry I'm not sure how to get the code blocks in comments! – MEric Jul 04 '13 at 06:25
  • make sure your python file is executable. also it will still not print to any terminal. you have to do the redirection as before. – mnagel Jul 04 '13 at 17:43
  • Cron's do NOT print to console, but they can output to files – Jonathan Apr 14 '15 at 22:20