PDA

View Full Version : set the date TZ within a cron job



how2
05-02-2011, 12:04 PM
Hi
I would like to have a cron job write a file using a date string as it's name.
I am able to get it working on my home Fedora 13 install but am having trouble here at BH.

Any help would be apprecianodo...


#### I try some experiments:

me@mysite.org [~/x/]# PS1="> "

> date
Mon May 2 12:39:57 MDT 2011

> TZ="GMT+4" date
Mon May 2 14:40:05 GMT 2011

> TZ="EDT+4" date
Mon May 2 14:40:36 EDT 2011

> TZ="EDT+4" date +%H
14

> TZ="EDT+4" date +\%Y\%m\%d-\%H%M
20110502-1442

> TZ="EDT+4" dstr=$(date +\%Y\%m\%d-\%H%M); echo $dstr;
20110502-1243

> dstr=$(TZ="EDT+4" date +\%Y\%m\%d-\%H%M); echo $dstr;
20110502-1444

> dstr=$(TZ="EDT+4" date +\%Y\%m\%d-\%H%M); touch x_$dstr; echo $dstr;
20110502-1445

> ls -gox*
-rw-r--r-- 1 0 May 2 12:45 x_20110502-1445


#### OK so then I try to get it into the cron job:

* * * * * dstr=$(TZ="EDT+4" date +\%Y\%m\%d-\%H%M); touch /home1/usr/x/x_$dstr;

> ls -go x*
/bin/ls: x*: No such file or directory


#### poop... How can I do this?Thanks, Howard();

how2
05-02-2011, 07:23 PM
I think this is working:

* * * * * dstr=$(TZ=EDT+4 date \+\%Y\%m\%d-\%H\%M); touch /home1/user/public_html/x/x_$dstr;

# It can have quotes too.
* * * * * dstr=$(TZ="EDT+4" date...

date \+\%Y\%m\%d-\%H\%M;
20110502-2027

> ls x*
x_20110502-2227