LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-13-2005, 10:05 AM   #1
MacSob
LQ Newbie
 
Registered: Oct 2004
Location: South Jersey
Distribution: Fedora Core X
Posts: 7

Rep: Reputation: 0
Question Rename file with date stamp


All,

I have just installed a new syslog server running Red Hat Enterprise Server 4. I've managed to get my firewalls to send their syslog information to this server and it's being logged to /var/log/firewall.log.

I have the following criteria I need to meet and am having some issues.

1. Back the file up hourly with the date and time automatically appended to the file name ex. 09132005_100000_firewall.log (or something like that) and copy it to /var/log/firewall. Create new firewall.log file. Repeat once per hour.

2. Once per day at midnight compress all 24 files into /var/log/firewall/backup/ with the filename being just the date.

This is something I very easily accomplished under Windows, but am having problems getting the command line context for appending date and time to the filename. Under Windows its something along the lines of %date%time.txt.

Any help greately appreciated.

Mac
 
Old 09-13-2005, 10:37 AM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
Take a look at Bash-Prog-Intro-HOWTO which should be on your system somewhere (like /usr/doc/Linux-HOWTOs) or at http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

In particular, the sections that mention a "Simple backup script".
 
Old 09-13-2005, 10:42 AM   #3
MacSob
LQ Newbie
 
Registered: Oct 2004
Location: South Jersey
Distribution: Fedora Core X
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks, I'll go through that and see what I can learn.

Mac
 
Old 09-13-2005, 11:32 AM   #4
MacSob
LQ Newbie
 
Registered: Oct 2004
Location: South Jersey
Distribution: Fedora Core X
Posts: 7

Original Poster
Rep: Reputation: 0
All,

I've found a nice and each way to accomplish the first part.

mv filename "`date +%Y%m%d_%H`_filename"

Any ideas on part two?

Mac
 
Old 09-13-2005, 12:00 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
This may get you started....

minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).

Edit your crontab
Fix the time and date positions to what you want.
* * * * * /mnt/backup/backup.job
Code:
Make a file called /mnt/backup/backup.job
#!/bin/bash
filename=`date '+%m%d%y'`
cd /Some/Dir/That/You/Have
/bin/tar -cvzf /var/log/firewall/backup/${filename}.tar.gz .

Last edited by homey; 09-13-2005 at 12:02 PM.
 
Old 09-13-2005, 01:35 PM   #6
MacSob
LQ Newbie
 
Registered: Oct 2004
Location: South Jersey
Distribution: Fedora Core X
Posts: 7

Original Poster
Rep: Reputation: 0
homey,

Thanks a lot for the assist! I'll keep plugging away at it and will post the final solution for you guys to review.

Mac
 
Old 09-13-2005, 02:30 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
You're welcome!
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
time stamp for file modification youngstorm Linux - Newbie 2 11-01-2005 04:46 PM
How can i Rename file? Khmer Linux - Newbie 4 10-21-2005 09:09 AM
Any programs to rename a image to it's EXIF date ? CRego3D Linux - Software 1 11-08-2004 03:25 PM
Time stamp in Samba is 11 hours behind time stamp in Linux Linh Linux - General 3 09-04-2003 01:44 PM
How to rename a file? juanb Linux - General 4 03-19-2003 12:20 PM


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