The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cron job starts new cron proccess ron76 SUN Solaris 3 05-12-2008 02:07 AM
Cron and Pseudo-Cron dingusmcghee UNIX for Dummies Questions & Answers 1 01-31-2008 12:58 PM
CRON usage for CRON job skyineyes UNIX for Dummies Questions & Answers 1 01-17-2008 10:17 AM
AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log Keith Johnson AIX 0 01-09-2008 08:32 PM
Cron : you are not authorized to use cron. Sorry. tt155 UNIX for Advanced & Expert Users 1 07-06-2005 11:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-02-2004
eludlow eludlow is offline
Registered User
  
 

Join Date: May 2004
Posts: 16
Cron

Could someone advise of the code to get a filename to have the date of creation in it?

I've the code to dump an SQL DB to a file, but would like it to have the date it.

Also, what is the code to get cron to execute a PHP (or perl) script at a set time?

Thanks,
Ed Ludlow
  #2 (permalink)  
Old 06-02-2004
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
For building a name with a datestamp, you can refer to what I have tried, quoted below, in the past in my auto build script. Just use the date command to formulate a date string:


Code:
TODAY=`date +%Y%m%d`

This creates a string like '20040602', which you can attach to the end of a fixed filename to create the final filename, like


Code:
mysql_$TODAY.sql

If you need to construct the date string in PHP, please consult the PHP manual.

As for invoking a PHP script from the command line, it should be as easy as something like

php script.php
perl script.pl

Just place this at the end of the cron line in place of the command to be executed.
  #3 (permalink)  
Old 06-03-2004
eludlow eludlow is offline
Registered User
  
 

Join Date: May 2004
Posts: 16
THanks for the reply. I've made the today variable in the way you say, but when it makes the backup file, it simply returns the file name as "backup_forum-date + %d-%m-%Y.sql"!!

What's going wrong?

Thanks,
Ed
  #4 (permalink)  
Old 06-03-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
In the code snippit that cgkihong posted, he is using back quotes( `). Be sure you are too! The back quote is the key to the left of the number 1 key on a standard keyboard.

You can also rewrite his code TODAY=`date +%Y%m%d` as follows (assuming Korn Shell is used):
TODAY=$(date +%Y%m%d)
  #5 (permalink)  
Old 06-03-2004
eludlow eludlow is offline
Registered User
  
 

Join Date: May 2004
Posts: 16
OK. Still having problems

So the first line of my crontab is:

TODAY=$(date +%d%m%Y)

and the filenamr part of the cron command is:

backup$TODAY.sql

So what is wrong?

That returns the filename: backup$(date +%d%m%Y).sql

Thanks,
Ed
  #6 (permalink)  
Old 06-03-2004
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
Works for me in ksh. Are you sure you are using ksh? If not, as google mentioned do:


Code:
TODAY=`date +%Y%m%d`

It's also good practice when using a variable without spaces next to the next character to enclose in curly brackets. So your cron code would look like:


Code:
backup${TODAY}.sql

  #7 (permalink)  
Old 06-03-2004
eludlow eludlow is offline
Registered User
  
 

Join Date: May 2004
Posts: 16
It's now returning

backup{`date +%d%m%Y`}.sql

as the filename!!!!!

I'm a newbie to Unix, so I hope I'm write in saying the declaration of the variable should go on the first line of the file that opens when you type "crontab -e"???

How do I find out if this is ksh or whatever?

Thanks,
Ed
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0