DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 11th August 2008
cwhitmore cwhitmore is offline
Port Guard
 
Join Date: May 2008
Posts: 27
Thanked 0 Times in 0 Posts
Default Using Date variable?

I'm writing a backup script and I'd like to include the date in the dump filename. How can I write on the date and not time/sec?
Reply With Quote
  #2   (View Single Post)  
Old 11th August 2008
graudeejs's Avatar
graudeejs graudeejs is offline
Real Name: Aldis Berjoza
formerly killasmurf86
 
Join Date: Jul 2008
Location: Riga, Latvia
Posts: 588
Thanked 29 Times in 26 Posts
Default

Code:
dump -0Lauf - /var | bzip2 > /home/var.dump-`date "+%d.%m.%Y."`bz2
this will result in
/home/var.dump-12.08.2008.bz2
Reply With Quote
  #3   (View Single Post)  
Old 11th August 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,154
Thanked 182 Times in 149 Posts
Default

I would use the international date format YYYY-MM-DD, so that a command like ls sorts them correctly
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #4   (View Single Post)  
Old 12th August 2008
cwhitmore cwhitmore is offline
Port Guard
 
Join Date: May 2008
Posts: 27
Thanked 0 Times in 0 Posts
Default

Great suggestions. Thanks.
Reply With Quote
  #5   (View Single Post)  
Old 12th August 2008
cwhitmore cwhitmore is offline
Port Guard
 
Join Date: May 2008
Posts: 27
Thanked 0 Times in 0 Posts
Default

I tried using the new varialbe name, but instead of creating a name with the date the filename comes out exactly as typed in the code above "var.dump- date +%d.%m.%Y.bz2"
What am I missing? I couldn't find anything on this at the freebsd site.
Reply With Quote
  #6   (View Single Post)  
Old 12th August 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Thanked 20 Times in 18 Posts
Default

Quote:
Originally Posted by cwhitmore View Post
I tried using the new varialbe name, but instead of creating a name with the date the filename comes out exactly as typed in the code above "var.dump- date +%d.%m.%Y.bz2"
What am I missing? I couldn't find anything on this at the freebsd site.
The orginal command is correct and you left out the backtick (`).
__________________
The power of plain text? It can control an entire OS
Reply With Quote
  #7   (View Single Post)  
Old 12th August 2008
cwhitmore cwhitmore is offline
Port Guard
 
Join Date: May 2008
Posts: 27
Thanked 0 Times in 0 Posts
Default

Oops. Thanks. That did it. Hard to tell the difference between ` and ' on the screen.
Reply With Quote
  #8   (View Single Post)  
Old 12th August 2008
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 194
Thanked 47 Times in 22 Posts
Default

You're missing backquotes (the ``), that way you tell script to execute whatever is in backquotes and use its result.
Examples:

$ echo date
$ echo `date`

$ echo cat /etc/pf.conf
$ echo `cat /etc/pf.conf`

Again see killasmurf's post carefully.

EDIT: There you go, one has to be fast around here!
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD
Reply With Quote
  #9   (View Single Post)  
Old 12th August 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

Some people may find the back-quotes visually confusing, here is another option:
$ dump -0Lauf - /var | bzip2 > /home/var.dump-$(date "+%Y.%d.%m").bz2

In this case, anything inside $(..) is executed.

EDIT: My sincere apologies, I forgot I was on the FreeBSD board.. the above will not work in csh.

Last edited by BSDfan666; 12th August 2008 at 07:59 PM.
Reply With Quote
Old 13th August 2008
phoenix's Avatar
phoenix phoenix is offline
Risen from the ashes
 
Join Date: May 2008
Posts: 699
Thanked 90 Times in 81 Posts
Default

But $(...) will work in sh, which is what all portable shell scripts should be written in. And anything that is run more than once or twice (like a backup routine) should be written into a script.
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[fman] tags out of date for ports BSDKaffee Feedback and Suggestions 1 12th June 2009 07:36 AM
echo tcpdump date to an output bsdnewbie999 Programming 8 8th April 2009 02:58 PM
Python: Use the value of a variable for calling another variable Carpetsmoker Programming 13 5th April 2009 05:53 PM
CSH 'mch' variable? JMJ_coder General software and network 1 12th February 2009 11:24 PM
HOWTO: Always install an up-to-date port chris Guides 8 28th May 2008 11:53 AM


All times are GMT. The time now is 11:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick