LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 07: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, 07: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, 09: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, 10:14 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 10: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, 11:05 AM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
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, 11:14 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 11:16 AM   #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, 11:34 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 11:52 AM   #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, 11:58 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Well done!
 
  


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

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

All times are GMT -5. The time now is 05:43 AM.

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