Probably working too hard for this cron question

Polytropon freebsd at edvax.de
Mon Jun 13 22:03:02 UTC 2011


On Mon, 13 Jun 2011 14:44:29 -0700, Kurt Buff <kurt.buff at gmail.com> wrote:
> Per the handbook, I added
> 
>      SHELL=/bin/sh
> 
> to crontab, and I also added
> 
>      #!/bin/sh
> 
> as the first line in the script
> 
> But, while a file is being created, it's just
> 
>      /root/-external1.txt
> 
> not
> 
>      /root/2011-06-13-external1.txt

Just a wild guess: How about adding {} to the variable
identifiers? There are some restrictions in how far a
character following the variable name will be treated
as a "stop sign", e. g. variable x, literal y, and you
have $xy which won't work, but $x_y may work, so you
use ${x}y to make sure the name is properly scoped.

Refering to your original script:

#!/bin/sh
dt=`/bin/date "+%Y-%m-%d"`
/bin/date > /root/${dt}-external1.txt
/usr/local/bin/curl -K /root/urls.txt >> /root/${dt}-external1.txt
/bin/date >> /root/${dt}-external1.txt

Could you try that?

As you mentioned ${dt} would be empty upon cron
execution, but not when run interactively, I would
guess that the execution of a value assignment keeps
its value just as long as it is within the same shell
environment (unless you set an environmental variable
via export command). If the script would be executed
by cron with one shell call per line... but I think
that it isn't done that way as it sounds too wrong...




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list