LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2008, 08:14 AM   #1
gelni
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
Cron Jobs with time not just date!


Hi all - my first post on here.

The command below works in respect of backing up a directly into a tgz file.

It adds the date - but how do I get it to add the time as well?

date=`date -I` ; tar -zcf public_html/backup_zip/backup_$date.tgz ./public_html/123/456/


Thanks

gelni
UK
 
Old 12-01-2008, 08:35 AM   #2
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
Code:
date +%d-%m-%g-%T
 
Old 12-01-2008, 10:41 AM   #3
gelni
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Time

Thanks but - I've inserted that code everywhere - but it does not work! Where shoud it go?
 
Old 12-01-2008, 11:14 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by gelni View Post
Thanks but - I've inserted that code everywhere - but it does not work! Where shoud it go?
What does "it does not work" mean? Do you know that the % sign has a special meaning if used in crontab?
 
Old 12-01-2008, 11:33 AM   #5
gelni
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Time

What I mean is that if I use this code in cron – “date=`date -I` ; tar -zcf public_html/backup_zip/backup_$date.tgz ./public_html/123/456/”

It will back up the entire directly as a .tgz - with the day month and year – all good.


But what do I amend the code to if I want to add the “time” it was backed up not just the dd/mm/yy?

I’m sure it is pretty simple – but any ideas what it would be?
 
Old 12-01-2008, 12:05 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Like datopdog said:

Code:
date=`date +%d-%m-%g-%T` ; tar -zcf /public_html/backup_zip/backup_$date.tgz ./public_html/123/456/
 
Old 12-01-2008, 12:14 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
In addition you can embed the command substitution directly in the file name:
Code:
tar -zcf /public_html/backup_zip/backup_`date +%d-%m-%g-%T`.tgz ./public_html/123/456/
but beware of the usage of the % sign in a crontab entry.
 
Old 12-01-2008, 12:16 PM   #8
gelni
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Tme

Thanks for the response - but - cut and pasted your text - checked and double checked it - and now get this error!!!

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

I know this should be simple - but what is it?
 
Old 12-01-2008, 12:34 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
I repeat for the last time: do you know about the meaning of the % sign in the crontab? See
Code:
man 5 crontab
to find out.
 
Old 12-01-2008, 12:52 PM   #10
gelni
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Yes – new line!

Problem solved by prefixing % with backslash

Thanking you all anyway.
 
Old 12-01-2008, 12:58 PM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Well done!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to convert windows date and time to unix date and time jitupatil_2007 General 8 03-31-2008 06:58 AM
cron hourly, daily, cron.d jobs don't execute eggsmartha Linux - General 3 09-17-2007 07:37 PM
Cron jobs not executed at right time(persistent UTC?) baddah Linux - Newbie 2 03-30-2006 12:27 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 11:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:39 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration