Yes, when I read my posting again, I realised that I've made some mistakes in which may cause some confusion. Sorry about that.
Here are the corrections.
For example:
Let's say the month of august 2010 is already over, so that means we now in september 2010. Based on my cronjob task on 1st of September, how to extract the log info of the previous month, in this case, August?
My script will always extract the the log info from the previous month.
Please kindly advice.
Thanks a lot.
Cheers.
---------- Post updated at 11:02 AM ---------- Previous update was at 10:56 AM ----------
Hi tyler_durden,
Thanks for your response.
When I tried your method, there are some errors as shown below. I'm unable to use your suggested option of date function.
# date --date='1 month ago' '+%b'
date: illegal option -- -
Usage: date [-u] [+format]
date [-u] [mmddhhmm[[cc]yy]]
date [-a [-]sss.fff]
# last -R | grep $(date --date='1 month ago' '+%b')
date: illegal option -- -
Usage: date [-u] [+format]
date [-u] [mmddhhmm[[cc]yy]]
date [-a [-]sss.fff]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvwx] pattern [file...]
When I checked my environment, it shows the following:
The solution will work only with GNU date, as mentioned in my earlier post. Do you have GNU date in your system ?
tyler_durden
Ok, just noticed you have HPUX. Search this forum for Perderabo's suite of shell functions that perform date arithmetic. Alternatively, you may want to use a scripting language to do the same.