I want to list all log files from log directory of previuos month.
suppose currnt month is december, i want to list all log siles of november.
if its april, it should list all files of march.

Please suggets.

Recommended Answers

All 4 Replies

find /var/log -mtime 30 -print

-mtime n
File’s data was last modified n*24 hours ago.
or
ls -R /var/log | grep Mar

However it really depends on what your logrotate configuration is set for. You may not be saving that far back.
ls -la /etc/logrotate.d
will give you what is set up to rotate and the config files will tell you how large or how often.

Thanks for the reply,

but my requirement is : find out a way which can make me see all the log files of full previous month when i execute it on any day of the current month.

for eg: if i execute command on 1st or 25th or 31st of the current month, it should list all the log files of the previous month (1-31 of previous month).

Hello,

There are several things to take into account when you say all log files from the previous month. You need to look at how the various log applications are storing your log files. Are they rotating the files at then end of the month or when the log gets to a certain size or at the end of the day.

For example if today is Aug 8th and your httpd log is set up to rotate when the size of the file exceeds 1MB and the access.log.1 log has entries from Jul 24th through Aug 2nd. it has a last access date of Aug 2nd but contains entries from the previous month. Does it show up in your list of last months logs or not? That is why I originally mentioned /etc/logrotate.d/ so you could go review the scripts doing the log rotations.

The other thing you have to consider is that different logs store data in different formats so how do you scan the different logs for the month in question?

Determining the previous month is really not a problem. You can quickly find the previous month by using the date command and subtracting 1.

date +%m
will give you the current month in numerical format

hi can u help me to find the number of days in a month using shell scripting ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.