This is something I've never really figured out the best way to do... It's pretty easy to get today's date in the format that you want with something like:
Code:
date +%y%m%d
The problem is getting yesterday's date. Since the "day" is the last field, you could take today's date and subtract 1, but that won't work on the first of the month. I've seen a lot of stuff in *nix that uses Unix time (great article on wikipedia:
http://en.wikipedia.org/wiki/Unix_time) to make it easy to do math on it, but converting back and forth can be a pain.
Thanks to you, I have learned something new today, and it's so simple! To get yesterday's date, try this:
Code:
date --date "$(date) 1 day ago" +%y%m%d
So to match those two files with yesterday's date and today's, you can do something like this:
Code:
#!/bin/sh
today=$(date +%y%m%d)
yesterday=$(date --date "$(date) 1 day ago" +%y%m%d)
echo "Today's date is: $today"
echo "Yesterday's was: $yesterday"
echo "Your command might look like:"
echo "/usr/local/bin/consolidate.pl /SERVER/ex${yesterday}.log /SERVER/ex${today}.log > /tmp/logfile.log"
## Output should look like this:
# Today's date is: 081112
# Yesterday's was: 081111
# Your command might look like:
# /usr/local/bin/consolidate.pl /SERVER/ex081111.log /SERVER/ex081112.log > /tmp/logfile.log
Hope this helps!