Help with script and grep the last date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script and grep the last date
# 1  
Old 05-12-2011
Help with script and grep the last date

Hi Guys,

I´ve a little question, perhaps somebody can help or have a hint for me ...

Here´s my problem:
We´ve a server which do at night an update of his virus-pattern, in /var/log/messages I can see if the update was successful or not, and mail the result to root

cutout of /var/log/messages:
Code:
...
May 12 06:01:27 hostname rtvscand: New virus definition file loaded. Version: 130511b.
May 12 06:01:27 hostname rtvscand: Download of virus definition file from LiveUpdate server succeeded.
...
...

Until now this was my procedure:
I´ve 2 scripts in my crontab

Code:
* 7 * * * root /root/sav-log.sh >> /var/log/sav-update.log
5 7 * * * root /root/sav-log2.sh

Here´s sav-log.sh:
Code:
/bin/echo "--------------------------------------------"
/bin/date
echo Script "SAV-LOG"
tail -8 /var/log/messages |grep rtvscand | awk '{ print $0 ;}'

and sav-log2.sh:
Code:
tail -4 /var/log/sav-update.log | mail -r root -s "SAV-Update" root

Until now this worked well, but now - because this server should become a Log-Server too, in /var/log/messages there were much entries from other servers also, so my script with "tail -8" don´t work, because "rtvscand" is now somewhere between other messages and not between the last 8.

Now I have to find out where is the last entry with "rtvscand"; it´s a little bit tricky because I can´t write for example tail -50 because it´s possible then that I get the result like this:

Code:
...
May 11 06:01:40 hostname rtvscand: New virus definition file loaded. Version: 130510c.
May 11 06:01:40 hostname rtvscand: Download of virus definition file from LiveUpdate server succeeded.
May 12 06:01:27 hostname rtvscand: New virus definition file loaded. Version: 130511b.
May 12 06:01:27 hostname rtvscand: Download of virus definition file from LiveUpdate server succeeded.
...

... but I want only the last day -> in this case May, 12

So I´ve to modify my script that only the entry with "rtvscand" with the
actual date will be found ....
perhaps something like this:
Code:
tail -50 /var/log/messages |grep "actual date" rtvscand | awk '{ print $0 ;}'


Perhaps somebody could help me?
Many thanks.
Regards
# 2  
Old 05-12-2011
Try this:
Code:
tail -50 /var/log/messages |
awk -v dat="$(date +'%b %d')" '$0 ~ dat && "rtvscand"'

# 3  
Old 05-13-2011
This worked ... many thanks.
Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

3. Shell Programming and Scripting

Script to copy creation date over top of modified date?

Can someone draw up a script that for every file, folder and subfolder and files that will copy the creation date over top of the modified date?? I know how to touch every file recursively, but no idea how to read a files creation date then use that to touch the modification date of that file,... (3 Replies)
Discussion started by: toysareforboys
3 Replies

4. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

5. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

6. Shell Programming and Scripting

grep with date

I have few files in one directory as below and I require the files that were created today... $ls -ltr -rw-r--r-- 1 abc abc 0 Dec 5 17:34 file4.txt -rw-r--r-- 1 abc abc 0 Dec 5 17:34 file5.txt -rw-r--r-- 1 abc abc 0 Dec 7 17:34 file6.txt -rw-r--r-- 1... (7 Replies)
Discussion started by: giridhar276
7 Replies

7. Shell Programming and Scripting

Calculating expiry date using date,sed,grep

Hi, I would greatly appreciate it if someone can help me with my problem. I have a crawler which collects spam URLs everyday & this data needs to be published in a blacklist. Here's the catch: The "Time To Live" (TTL) for each URL is 3 months (or whatever for that matter). If i see the... (5 Replies)
Discussion started by: r4v3n
5 Replies

8. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

9. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

10. Shell Programming and Scripting

Grep date from ls -l

I have a script which required the month and day as the input ex : ./script <Month> <date> from this I get the list of files to do further logics. The problem is when I assign these $1 and $2 to variables, and use grep command in the script ls -l |grep "$1 $2" it works fine for two... (1 Reply)
Discussion started by: GenMen
1 Replies
Login or Register to Ask a Question