LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I save a name-date changing file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-save-a-name-date-changing-file-491559/)

Xolotl 10-11-2006 05:06 PM

How do I save a name-date changing file?
 
I just set my first CRON job to run a backup using DUMP.

I want the name of my backup to be 'BKUPMMDDYY'
where:
MM= month
DD= day
YY= year

So, how can I get this pickup the appropriate date? Do I need to create an script?

Thanks.

gilead 10-11-2006 05:26 PM

The following should work (use the variable $OUTPUTNAME as the file name):
Code:

OUTPUTNAME="BKUP`date '+%m%d%y'`"

Xolotl 10-12-2006 04:58 PM

Gilead, thanks for your help.

When I ran the command from the console, it works just fine:
[root@wxyz: root] $ /sbin/dump -0u -a -f /temp/dbkup/"bkup_`date '+%m%d%y'`" /home


But, when I run it from my crontest, I get a syntax error:


MAILTO=myusername@mydomain.com
00 12 * * * /sbin/dump -0u -a -f /temp/dbkup/"bkup_`date '+%m%d%y'`" /home



This is what the cron deamon emails to me:

Syntax error: EOF in backquote substitution


Do you have any idea why is this happening?

gilead 10-12-2006 06:04 PM

It could be that the date command isn't in the path used by the cron daemon. Can you try it with /usr/bin/date instead (or whatever the path is to date on your system)?

Xolotl 10-13-2006 06:25 PM

I found several paths and try them all with no luck. I am actually running FreeBSD (6.1), but this should not be too different, right?

Thanks.

gilead 10-14-2006 02:21 AM

I'd have thought the operation would be the same since it works at the command line. Can you try putting the command into a script and running the script from cron (I don't know how BSD parses the command to be run in cron)?

Tinkster 10-14-2006 02:40 AM

And on an unrelated note: if you want to be able to sensibly
sort your backup-files later on I'd recommend ymd instead of mdy.


Cheers,
Tink

Xolotl 10-20-2006 04:28 PM

Thanks guys! I end up writing a little script and it worked just fine that way.;)


All times are GMT -5. The time now is 10:10 PM.