36

I've got such situation: I want to schedule a job with crontab on a linux server. I'm not super-user, so I'm editing (with crontab -l, editor vim) only my crontab file. For testing, I put there:

* * * * * echo asdf

And the job is not running. Is the restart of the server needed? Or maybe some administrator move?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
zlenyk
  • 922
  • 2
  • 7
  • 22
  • Check your e-mail. Output of `cron` jobs doesn't go to your terminal, since `crond` doesn't know where your terminal is. Depending on your system configuration, it's typically sent to the owner by e-mail (which may or may not be possible). `man cron` for more information. – Keith Thompson Mar 04 '15 at 17:08

3 Answers3

52

May be it is, cron jobs will run in their own shell. So you can't expect to see asdf on your console.

What you should try is

* * * * * echo asdf > somefile_in_your_home_directory_with_complete_path.log

Next check the file by doing a tail:

tail -f somefile_in_your_home_directory_with_complete_path.log

And if it's not, check if the cron daemon itself is running or is down:

# pgrep crond

OR

# service crond status
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Kedar Parikh
  • 1,241
  • 11
  • 18
6

If you want to echo something on your shell you could use wall:

* * * * * wall <<< "Hello from cron"
* * * * * echo "Hello from cron" | wall

These two lines basically do the same but the first one might not work on older shell, just choose your favorite.
Anyway, be aware that wall will send your message to every user currently connected.

Alex
  • 448
  • 6
  • 11
2

For me * * * * * /bin/echo text > file is not working...I don't know why, previleges and everything is set. (This command is running normaly when I execute it as the particular root user, just to clarify this.) This can be solved by injecting the path PATH=$PATH:/bin in my example.

Instead * * * * * echo text > file is working fine, probably path issue.

Hope I helped