Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

how can I check the logs of previous 10 days ?

SOLVED
Go to solution
Maaz
Valued Contributor

how can I check the logs of previous 10 days ?

how can I check the last ten days logs of cron(from /va/log/messages)

Regards
Maaz
7 REPLIES
Steven E. Protter
Exalted Contributor

Re: how can I check the logs of previous 10 days ?

Shalom,

cd /var/log

ls -lrt

That will reverse order display by date so you know what has been updated recently.

/var/log/messages is in order and I would suggest using the tail command.

I personally would just use vi and ctrl-g to get to the bottom of the file.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Maaz
Valued Contributor

Re: how can I check the logs of previous 10 days ?

Hi Thanks SEP for the reply/help

>cd /var/log
>ls -lrt
>That will reverse order display by date so you know what has been updated
>recently.

I dont need the above solution

>/var/log/messages is in order and I would suggest using the tail command.

I just want to check the last 10 days messages from /var/log/messages, for a specific daemon e.g 'cron'

yes, tail could be the an option, but help me
how can I use tail to check the logs of last 10 days

Regards
Maaz
Maaz
Valued Contributor

Re: how can I check the logs of previous 10 days ?

is the following possible ?
I just want to check the last 10 days messages from /var/log/messages, for a specific daemon e.g 'cron'
Huc_1
Honored Contributor

Re: how can I check the logs of previous 10 days ?

Would some form of the below be what you are looking for ?

# find /var/log/ -name "messag*" -exec grep -B3 -A3 -i "cron" {} \;

Enjoy life.

Jean-Pierre Huc
Smile I will feel the difference
Ivan Ferreira
Honored Contributor

Re: how can I check the logs of previous 10 days ?

You will have to use grep, but without some scripting, hard to find specific ten days.

For example:

grep Mar messages | grep

But, remember that cron handles it's specific log file /var/log/cron.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Roman Schmidt
Frequent Advisor
Solution

Re: how can I check the logs of previous 10 days ?

This would return the syslog entries of the last 10 days:

for ((i=0;i<11;i++)); do grep "$(date --date="$i days ago" +%b' '%d)" /var/log/syslog; done


take care, if the date is below 10 maybe there's a space missing in the grep. Try around a bit, that example should be a nice base for improvements :)
Maaz
Valued Contributor

Re: how can I check the logs of previous 10 days ?

Hi everyone, thanks for nice help

Roman Schmidt thanks for excellent help

>take care, if the date is below 10 maybe
>there's a space missing in the grep. Try
>around a bit
yes you are right, I just did a small change and now its working even when the date is below 10

for ((i=0;i<11;i++)); do grep "$(date --date="$i days ago" +%b' '%e)" /var/log/messages |grep "cron"; done

i.e instead of '%d' I use '%e' with 'date', and its working with the date below 10. ;)

Thanks
Regards
Maaz