?
Solved

Shell script: date yesterday

Posted on 2005-04-29
3
Medium Priority
?
2,347 Views
Last Modified: 2012-06-21
I have a direcotry /var/log/compnaam/! In this directory all log files from different machines are logged in this format:

mail.29.04.2005
syslog.29.04.2005
onzin.29.04.2005
etc
etc

Now i'm trying to write a script that greps files with a specfic date (the date of the day before, so lets say it's 30-04-05, then i want t he script to get 29-04-05).
so it needs to grep all files with the date of yesterday, after that it needs to be zipped ( won't be a problem ).

Who can help me out since i'm not a genius shell scripter and don't have much time to open a book and start learning.

thnx in advance
0
Comment
Question by:Mr-sark
  • 2
3 Comments
 
LVL 4

Expert Comment

by:bytta
ID: 13893071
date +%d-%m-%Y -d yesterday
0
 
LVL 4

Accepted Solution

by:
bytta earned 600 total points
ID: 13893209
To be more precise...
If your yesterday's files are all  /var/log/compnaam/<something>.28.04.05

day=$(date +%d.%m.%Y -d yesterday);
tar zcf archive.$day.tar.gz   /var/log/compnaam/*.$day

would result in all the files being tarred an gxipped into archive.28.04.05.tar.gz
0
 
LVL 1

Author Comment

by:Mr-sark
ID: 13893651
wow it works great thnx
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question