Shell script: date yesterday

Posted on 2005-04-29
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:


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
Question by:Mr-sark
    LVL 4

    Expert Comment

    date +%d-%m-%Y -d yesterday
    LVL 4

    Accepted Solution

    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
    LVL 1

    Author Comment

    wow it works great thnx

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now