Daily grep on a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Daily grep on a log file
# 1  
Old 09-07-2010
Daily grep on a log file

Hi,
I would like to execute a daily grep like:
grep 2010-09-06 statistics.log|grep API > /var/tmp/stat20100906_sp.txt

On date e.g. 2010-09-07 run a grep on yesterday's date, from the result grep the word "API" put all in /var/tmp
Would like to have a script configured in the crontab, running a grep on "yesterday's" date and put in in /var/tmp.

Today I execute this manually each day...Smilie

P.S. O/S = Solaris (bash)
# 2  
Old 09-07-2010
If your date command doesn't support -d "yesterday", then read it:
https://www.unix.com/answers-frequent...rithmetic.html

Otherwise, test below script and put in cronjob.

Code:
d1=$(date -d "yesterday" +%Y-%m-%d)
d2=$(date -d "yesterday" +%Y%m%d)
grep $d1 statistics.log|grep API > /var/tmp/stat${d2}_sp.txt

# 3  
Old 09-07-2010
-d "yesterday" not supported...
# 4  
Old 09-16-2010
-d not supported

Tried the script, -d is not supported.Smilie
Any idea?Smilie
# 5  
Old 09-16-2010
Code:
perl -e '@T=localtime(time-86400);printf("20%02d-%02d-%02d\n",($T[5]+1900)%100,$T[4]+1,$T[3])'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

2. Fedora

/var/log/btmp size 2.2Gb daily

Hello, One Fedora server is facing the issue that daily /var/log/btmp grows to 2.2Gb or more. I need your help to determine the cause and isolate it. Thank you! (6 Replies)
Discussion started by: feroccimx
6 Replies

3. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

4. Shell Programming and Scripting

How to send file from windows to UNIX daily?

Hi All! I am trying to write a little script that should go to a windows server get one file and put on a unix server, but I am not sure if it is the right way please help: #! /usr/bin/sh HOST=10.100.48.41 USER=ftp_hm PASSWD=P@$$w0rd ftp -n $HOST quote user $USER quote pass $PASSWD... (7 Replies)
Discussion started by: fretagi
7 Replies

5. Red Hat

UNIX script for daily file transfer ???

I need to create a script which needs to transfer the "<filename>+yyyymmdd".dat file from a unix machine to a linux machine.. daily. we can use an active batch to schedule the script. however, the script needs to detect if the new file is present, if present, then transfer. any help ?? (1 Reply)
Discussion started by: ravikodi
1 Replies

6. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

7. Shell Programming and Scripting

Shell Script to grep Job File name and Log File name from crontab -l

Hello, I am new to shell scripting. I need to write a shell script where i can grep the name of file ie. .sh file and log file from crontab -l. #51 18 * * * /home/oracle/refresh/refresh_ug634.sh > /home/oracle/refresh/refresh_ug634.sh.log 2>&1 #40 17 * * * /home/oracle/refresh/refresh_ux634.sh... (1 Reply)
Discussion started by: guptra
1 Replies

8. UNIX for Dummies Questions & Answers

Daily File Checks

Hello all, I'm sorry if this is answered elsewhere, I've used the search function and can't find the specifics of what I'm after. I am brand new to playing with linux, and ideally I want to get better to help the company that I now work for. What I want to do: Create a script that I... (4 Replies)
Discussion started by: Aussiemick
4 Replies

9. UNIX for Dummies Questions & Answers

Showing a daily backup job from a unique log file.

Hi guys, I´m a newbie in Linux, but I´m trying to solve some problems studying on my own, but I´ve had some problems with AWK. Look, I have one single backup log file per server and I want to make a daily delection from the last backup job to show in a intranet of my work. The log files are from... (0 Replies)
Discussion started by: metalfreakbr
0 Replies

10. Shell Programming and Scripting

monitor daily file uploads

hey all, i am a shell scripting n00b so bear with me. i got a server that every night uploads one file to a remote server. the file is prodserver_date_time. i would like to make a script, run by root on a daily cron job. i want it to determine if the file was received or not. no md5... (2 Replies)
Discussion started by: jweinraub
2 Replies
Login or Register to Ask a Question