LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2015, 03:11 PM   #1
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
Trying to get 'date' to work in 'cron'


Quote:
dave@dave:~/Gigs$ date --version
date (GNU coreutils) 8.21
Ubuntu 15.04
Cron & crontab manuals show a date of 2010. Is this the latest versions?

Three weeks I have tried solutions I found on google, stackoverflow, WW3, ubuntu forums, linus questions and a bunch of other places. I've not found much dealing with cron and date, what I did find I evidently did not understand completely as a lot of it dealt with internal workings.

I'm not sure what question to ask. Can someone point me in the right direction?
TIA
Dave

At 11:00 pm I need to capture todays date and store it. At 3:30 am I will use this to remove expired files for a list.

Code:
# m h  dom mon dow   command
#works as expected
52 10 * * * mplayer ~/Music/Spanish_Mary.mp3

#works from the command line but not cron
48 23 * * * ~/bin/scrub_gig_list_time.sh
#scrub_gig_list_time.sh
##!/bin/bash
#create a date tag to scrub the giglist of expired events.
#date '+%m/%d/%Y' >> ~/Gigs/oldgigs
#echo "Done"

#Works from the command line but not cron
# I have tried botkh escaping and  unescaping the '%' and '>' & '>>'
13 51 * * * /bin/date '+\%m/\%d/\%Y' >> gigstoeeraise
 
Old 07-31-2015, 03:21 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
What do you mean it doesn't work? What does it do? Do you receive any mail from cron? Do any of the files you're redirecting to get created? If so, do you see any errors in them?

Also, you shouldn't use "~" in cron or scripts, use $HOME, and you should use the absolute path to all files (not just "gigstoeeraise"). You don't need to delimit the redirects btw.

And why are you using "51" for the hour in your last cron entry?

Last edited by suicidaleggroll; 07-31-2015 at 03:23 PM.
 
1 members found this post helpful.
Old 07-31-2015, 03:34 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,744

Rep: Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924
In additon cron has a very limited path environment and it is best to use the full path. However, you really do not need a cron job to capture yesterdays date and save it to a file. In your removal script use:

date --date="1 day ago" +%m/%d/%Y

Last edited by michaelk; 07-31-2015 at 03:35 PM.
 
Old 08-01-2015, 09:21 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,148

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
Have you set the timezone in your crontab?
 
Old 08-06-2015, 02:03 AM   #5
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
Marking this solved. Not using Bash/Cron.

Using PHP
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [cron] Root cron ib centos 6.3 doesn't work/ killout Linux - Newbie 2 12-17-2012 01:26 PM
[SOLVED] Stoping the cron at particular time and date manju98458 Linux - Newbie 16 11-21-2012 06:17 AM
Cron Jobs with time not just date! gelni Linux - Newbie 10 12-01-2008 11:58 AM
Cron job files by date Kumado Linux - General 4 04-26-2006 05:02 PM
using date in cron cbriscoejr Linux - Distributions 5 01-06-2005 07:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration