getting the date in crontab command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux Go Back    


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 !!

getting the date in crontab command

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-11-2007
pranavagarwal pranavagarwal is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 13 May 2013, 11:46 AM EDT
Location: India
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
CPU & Memory getting the date in crontab command

Hi All,
There is a requirement to create a file everyday using the cronjob with the date as its name.

any suggestions for the crontab command that'll serve this purpose?

e.g.

Code:
02 30 * * * touch abcd.`date +%d.%m.%y`

needless to say.. this doesn't work..

looking fwd to lots of sugestions..Unix or Linux Image
Sponsored Links
    #2  
Old Unix and Linux 12-11-2007
porter porter is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Last Activity: 8 January 2008, 6:50 PM EST
Posts: 2,965
Thanks: 0
Thanked 5 Times in 5 Posts
Put all the logic in a script that you call from crontab.

Then you can setup the environment, set the current directory, test the script in isolation etc.
Sponsored Links
    #3  
Old Unix and Linux 12-11-2007
prowla prowla is offline
Read Only
 
Join Date: Nov 2007
Last Activity: 16 July 2012, 4:02 PM EDT
Posts: 165
Thanks: 0
Thanked 2 Times in 2 Posts
Why not try preceding the commands with their path (eg. /usr/bin/touch abcd.`/usr/bin/date +%d.%m.%y`)?

I would also suggest putting your timestamp year.month.date, as your files will show up in order in ls listings then.
    #4  
Old Unix and Linux 12-11-2007
pranavagarwal pranavagarwal is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 13 May 2013, 11:46 AM EDT
Location: India
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Error may I be a li'l clearer?

I think that I was not clear about what I want here.

All that I want is to touch a file everyday at 2:30 with name as

Code:
day.12.11.2007

i have this example of..

Code:
30 02 * * * * * * touch /home/pranav/abcd-`date +%d.%m.%y`

`

but it doesn't work, leave alone do what i want..
expecting the date command should work as it does at the prompt, but seemingly commands between ` ` are not executed becuse it IS creating the file but as "abcd-". That's it.

@porter..
Sorry, I didn't get you.. if you'd understood and ur post is still applicable.

@prowla..
thanx for pointing out..

Last edited by pranavagarwal; 12-11-2007 at 04:50 AM.. Reason: elaboration
Sponsored Links
    #5  
Old Unix and Linux 12-11-2007
pranavagarwal pranavagarwal is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 13 May 2013, 11:46 AM EDT
Location: India
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Lightbulb ohh..

@porter..
ohh.. i did understand your post but only now.. Unix or Linux Image
the point is to do it using a crontab.. i wouldn't have asked it else.. Unix or Linux Image

Unix or Linux Imagethanxes..
Sponsored Links
    #6  
Old Unix and Linux 12-12-2007
awk awk is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 29 May 2012, 11:56 AM EDT
Posts: 135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pranavagarwal View Post
Hi All,
There is a requirement to create a file everyday using the cronjob with the date as its name.

any suggestions for the crontab command that'll serve this purpose?

e.g.

Code:
02 30 * * * touch abcd.`date +%d.%m.%y`

needless to say.. this doesn't work..

looking fwd to lots of sugestions..Unix or Linux Image
Not sure how useful this will be - AIX handles it just fine -

55 09 * * * touch `date +abcd.\%m.\%d.\%Y.dat`

Same thing in SUN doesn't. But an interesting problem.

If you leave off the backslashes, SUN treats the rest of the line following the % as a comment and ignores.

The only way I can think of to try and get around, is to put the command in a script, that you execute as a cron job.
Sponsored Links
    #7  
Old Unix and Linux 12-12-2007
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 March 2015, 10:08 AM EDT
Location: Foxborough, MA
Posts: 7,764
Thanks: 170
Thanked 633 Times in 591 Posts
'man crontab' yeilds:

Code:
     The sixth field of a line in a crontab file is a string that
     is  executed  by the shell at the specified times. A percent
     character in this field (unless escaped by \) is  translated
     to a NEWLINE character.

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Crontab date setting problem beginningDBA Solaris 2 04-05-2012 09:26 PM
time and date in script/crontab lenora Shell Programming and Scripting 2 02-11-2011 02:47 PM
date command issue from crontab pritish.sas Shell Programming and Scripting 1 06-01-2010 06:43 PM
date command issue from crontab pritish.sas Shell Programming and Scripting 1 05-28-2010 03:24 AM
why the date format dont work in crontab p4cldba UNIX for Advanced & Expert Users 7 06-30-2008 08:09 PM



All times are GMT -4. The time now is 03:21 AM.