Cron redirect problem

Hello all,
I have a script that I am trying to execute and redirect the output to a file, but I have trouble in redirection. The cron job is running properly as I see it in the mail.

This is what I am doing

In crontab file,
0 4 * * * somescript.sh > /some_location/`date '+%m%d%y_%H%M'`.log

What is it that I am doing wrong?
Please help!!

I have no such problem. On Solaris it works.

But try using /usr/bin/date.

Does "some_location" exist? Is it writable by the user running the cronjob?

Does it produce any output to stdout? Maybe add 2>&1 to it's end to catch stdout and stderr.

Its on Solaris itself.

The location is writeable.

I tried running the script and redirecting the output, it works but cannot do it with cron for some reason.

# ./somescript.sh > /some_location/`date '+%m%d%y_%H%M'`.log is working

@zaxxon,
I tried that too, but of no use.

does

/var/cron/log

contain some info on this? error messages, whatever..?

There is no error in /var/cron/log. It says the script executed on time.

Seems this could go on for days!

You have to take some initiative. Try something different. Does your script direct the output somewhere else? Does it play around with file descriptors? Did you check your mail? If it's not that sensitive, post the script so we can see what it's doing. Change your cronjob to write to /tmp instead of "some_location". Play around with it a bit.

There's no reason I can think why it shouldn't do what you expect, and from what you've given us it should, but it doesn't help if ypur script can only run at 4 in the morning!

Actually the script runs every 4 hours, I just displayed it as 4 to avoid the hassle. And I cannot display the script as it doesn't belong to me and it belongs to a business critical application. I saw the script and everything seems to be straight forward. But I don't understand the reason for it to not redirect the output.

4 things you can do:

  1. Check "/some_location" for a file name .log . If it's there, that tells us that your cron won't do command expansion (the backticks), and you'll have to find another way to add that to the log file name (maybe through a wrapper script)
  2. Write the log file to /tmp / /var/tmp / some other location that's guaranteed to be writeable and not full
  3. Check the mail for the user owning the crontab entry. Any output written to stdout/stderr is usually sent via local mail
  4. Check the script itself for any stuff like
    text exec 1>... exec 2>...
    as those are redirections that take precedence over anything you might do from within cron

As scottn said, show some initiative, instead of feeding us one tidbit at a time.

try this:

bash -c "somescript.sh > /some_location/`date '+%m%d%y_%H%M'`.log"

cron run commands on a subshell. try running your command on its own shell by passing the entire command as an argument to the shell. also, use the full path of date and bash or sh.