List/Range Todays Log.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List/Range Todays Log.
# 1  
Old 06-07-2010
Question List/Range Todays Log.

Hi All,
I am mediator Shell programmer, Just have an hands on experice :-), i am writing a shell scirpt to list logs of todays date from /var/log/messages.

I need to ur kind help where if i run this script from cron. the script should filter todays logs only from /var/log/messages.

Below is the script .....

#################################################
Code:
#!/bin/bash
set nowrap
date="`date |awk '{print $2 " " $3}'`"
temp1="/root/riskadm.log_`date +%F`"
#temp2="/root/testadm.log_`date +%F`"
grep "$date" /var/log/messages |grep riskadm |grep su >> $temp1

here its not listing todays logs from /var/log/messages.


Kindly assist

Thanks again !

Regards

Last edited by Franklin52; 06-08-2010 at 05:13 AM.. Reason: Please use code tags!
# 2  
Old 06-07-2010
Hi Anand,

If the date is between the 1st and the 9th of the month you need to add another space between the day and the month in order to grep /var/log/messages, e.g.:
Code:
date="Jun  7"

# 3  
Old 06-07-2010
Hi Scrutinizer,
Thanks for your time, I got that but i need this script to automatically take the month and date and extract the logs.I dont have to mentioned June or July etc.. It should automatically list the MOnth and Day logs ...

Thanks !
# 4  
Old 06-07-2010
Hi anand,

Do you mean something like this:
Code:
gdate=$(date '+%b %e' | awk '{printf "%s %2s\n",$1,$2}')

or
Code:
gdate=$(printf  "%s %2s\n" $(date '+%b %e'))

Which will put today's date in the variable $gdate, so the has the right format to grep /var/log/messages with
# 5  
Old 06-07-2010
Thats something superb... Thanks Scrutinizer
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert list of numbers to text range

Hi, I'd like to take a list of numbers (with a prefix) and convert to a range, for example: cn001 cn004 cn016 cn017 cn018 cn019 cn020 cn021 cn031 cn032 cn038 cn042 cn043 cn044 cn045 (5 Replies)
Discussion started by: chrissycc
5 Replies

2. UNIX for Beginners Questions & Answers

How to list todays file in perticular folder?

How to list todays file in perticular folder Moved thread to appropriate forum (9 Replies)
Discussion started by: pspriyanka
9 Replies

3. Shell Programming and Scripting

How to list todays and yesterdays .rej files from a directory?

I am trying to display todays and yesterdays .rej files from a directory. ls -lrt *.rej | grep 'Aug 12' ; ls -lrt *.rej | grep 'Aug 13' Which is working as above. But i want take 'Aug 12' and 'Aug 13' from a variable and the command should work everyday. I am able to get todays files by... (9 Replies)
Discussion started by: GopalKrishnaP
9 Replies

4. Shell Programming and Scripting

Using 'date' to list a range of dates

Hi guys, I have been trying to create a list of dates from a certain range, ie. range from 01011950 to 31122000 But when my below code reaches certain dates, it comes up with a; 'date: invalid date 'yyyy-mm-dd -d 1day' Sofar I have come up with the following, slow and ugly; ... (4 Replies)
Discussion started by: TAPE
4 Replies

5. Shell Programming and Scripting

List files with Date Range and Zip it

Hi all, I am using the below script which display the files in the folder with the date range we specify. I want to add extra functionality that, The listing files should be zipped using gzip. I tried to add exec gzip at the last line but it is not working. Suggestions please. ... (2 Replies)
Discussion started by: nokiak810
2 Replies

6. Shell Programming and Scripting

Create range from a list

Hello everyone, I am trying to create a script that will make a range or ranges based on a sorted list of numbers. Eg. If the list is like 1 2 3 4 5 6 7 12 13 14 15 The output range should be: 1-7 12-15 (9 Replies)
Discussion started by: run_time_error
9 Replies

7. UNIX for Dummies Questions & Answers

List-to-Range of Numbers

Hello, I have two columns with data that look like this: Col1 Col2 ------ ----- a 1 a 2 a 3 a 4 a 7 a 8 a 9 a 10 a 11 b 6 b 7 b 8 b 9 b 14 (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

8. Shell Programming and Scripting

How to list todays file

Hi Friends, How to list todays file from a directory listing of files for amny dates. I tried with the following options but not working : find . -name "esi01v*" -mtime 1 -ls find . -name "esi01v*" -ctime 1 -ls find . -name "esi01v*" -mtime 1 Please advise (19 Replies)
Discussion started by: unx100
19 Replies

9. Shell Programming and Scripting

Creating a range out of a broken list

Hi all, I am trying to create a file which has one or more ranges based on a file containing a long list. The problem is that the file which has this list is not continuous and is broken in many places. I will try to illustrate by an example: The List File: 1 2 3 4 5 6 9 10 11 12... (5 Replies)
Discussion started by: run_time_error
5 Replies

10. Shell Programming and Scripting

to get list of files of a perticular range of time

hi, how to list the files which has been created or accessed before 6 months thanks (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question