Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

how to create a file named $date?(bash experts)

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
6 posts • Page 1 of 1
Author
Message
stillman
Apprentice
Apprentice
User avatar
Posts: 223
Joined: Sat Dec 07, 2002 6:01 pm
Location: Vienna, Austria

how to create a file named $date?(bash experts)

  • Quote

Post by stillman » Sat Sep 10, 2005 10:19 am

i have a lot of log files that can not be gripped by metalog, like named-logfiles and asterisk-logs. now i'd like to add a cronjob to gzip these files(also config-files would be nice) and name the file by the date the archive has been created, additionally adding directories for every month and move those archives in the monthly dirs. though i'm not very keen on bash yet so i can't figure out how to create a file named with the date(i had several attempts though)...:roll: anyone here having mercy and tell me how i could "touch ${date}"?
Top
tomvollerthun
Guru
Guru
User avatar
Posts: 316
Joined: Sat Mar 19, 2005 2:56 pm

  • Quote

Post by tomvollerthun » Sat Sep 10, 2005 10:26 am

I make it like this:

Code: Select all

date=`date +%d%m%g`
touch $date
That presumes that you have the date-command which belongs to coreutils, but I think most boxes will have it.

If you don't like the day-month-year format, see man date ;)

cu, tom
Computer science is no more about computers than astronomy is about telescopes.
Dijsktra
---------------
Don't believe my "Guru" status!
Top
Earthwings
Bodhisattva
Bodhisattva
User avatar
Posts: 7753
Joined: Mon Apr 14, 2003 8:13 pm
Location: Germany

  • Quote

Post by Earthwings » Sat Sep 10, 2005 10:31 am

As a sidenote, isn't that what logrotate is for?
KDE
Top
i92guboj
Bodhisattva
Bodhisattva
User avatar
Posts: 10315
Joined: Tue Nov 30, 2004 8:17 pm
Location: Córdoba (Spain)

  • Quote

Post by i92guboj » Sat Sep 10, 2005 10:35 am

The easiest is to use the output of the date command as the input for touch (or whatever other program).

Code: Select all

$ touch `date`
No that the little things are not single quotations ( ' ) but reverse accents (`). Bash expands the contents of anything inside this accents to the output wich results of the running of that contents, in this case, the command "date".

Another very tipical example is the use of this thing to locate the current running kernel modules directory:

Code: Select all

cd /lib/modules/`uname -r`
Top
stillman
Apprentice
Apprentice
User avatar
Posts: 223
Joined: Sat Dec 07, 2002 6:01 pm
Location: Vienna, Austria

  • Quote

Post by stillman » Sat Sep 10, 2005 10:39 am

thx guys!

@Earthwings:yes, but can you advice logrotate to gzip the files as well? and i want to make backups of my configs as well...
Top
Earthwings
Bodhisattva
Bodhisattva
User avatar
Posts: 7753
Joined: Mon Apr 14, 2003 8:13 pm
Location: Germany

  • Quote

Post by Earthwings » Sat Sep 10, 2005 12:37 pm

You can activate compression in /etc/logrotate.conf. logrotate is not a backup tool for config files, that's right.
KDE
Top
Post Reply

6 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic