Retrieve logs for last 4 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieve logs for last 4 hours
# 8  
Old 11-22-2010
The code below should work(NOT tested).
Code:
ssh user@IP /bin/bash <<\EOF 
	awk ' BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(/[-: ]/, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /home/user/log.txt
EOF >> erroroutput.txt

# 9  
Old 11-23-2010
Thanks kevin.It worked with some modifications.
Code:
ssh user@IP /bin/bash  <<\EOF
awk ' BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(/[-: ]/, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' home/user/log.txt >  erroroutput.txt
EOF

But errorOutput.txt is getting created in the remote server and not in our local server.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 11-23-2010 at 09:01 AM.. Reason: Code tags, please...
# 10  
Old 11-23-2010
You put "> erroroutput.txt" inside the EOF pair, so erroroutput.txt is supposed to be created on remote server.
Actually you can save the code in the following in a file, let's name it, fetch_log.sh
Code:
ssh user@IP /bin/bash <<\EOF 
	awk ' BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(/[-: ]/, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /home/user/log.txt
EOF

make it an executable from shell chmod +x fetch_log.sh, and you run ./fetch_log.sh > erroroutput.txt, I think this should satisfy your requirements.
# 11  
Old 11-23-2010
We are remoting to six different servers,so the error file is getting created in these 6 servers.We need to append all these into a single file in our local machine so that we can mail it.So we are using a single shell script with for loop to login to 6 servers.So your redirection on the call of the script might not work here.
# 12  
Old 11-23-2010
Quote:
Originally Posted by Deepthz
We are remoting to six different servers,so the error file is getting created in these 6 servers.We need to append all these into a single file in our local machine so that we can mail it.So we are using a single shell script with for loop to login to 6 servers.So your redirection on the call of the script might not work here.
That is not an issue, just use ">>" instead of ">".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Get the no of hours between days

Hi, i have a date 1- 2013101511 date2 -2013101812 need toget the no of hours between them,can any one tellme the logic. (6 Replies)
Discussion started by: sandeep karna
6 Replies

3. AIX

cron off by 5 hours

stupid question im sure, but its frustrating My cron jobs are off by 5 hours. My system time is right but all of my cron jobs are running approximately 5 hours late. Any idea why? (4 Replies)
Discussion started by: mshilling
4 Replies

4. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

5. Shell Programming and Scripting

Command to clear logs for every 6 hours in solaris

Hi Folks, I need to remove log files for six hours on Solaris. before i used to do for every 24 hours below is the code for 1 day older log files, now i tried using -mmin +360 but it says command not found. Can someone please help me out!!! part of the code: LOG_FILE=`find /home/Logdir... (1 Reply)
Discussion started by: Sendhil.Kumaran
1 Replies

6. Shell Programming and Scripting

Retrieve logs for previous 4 hours

Hi, I am in the process of configuring a script, and i intend it to retrieve logs for previous four hours, and then scan for predefined errors. I am kind of stuck on the log retrieval part where the script will run early morning like 1 AM or 2 AM, the command as posted below will give me... (4 Replies)
Discussion started by: john_prince
4 Replies

7. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

8. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

9. Post Here to Contact Site Administrators and Moderators

Have we just had a rollback of a few hours?

Have we just had a rollback of a few hours? (1 Reply)
Discussion started by: porter
1 Replies

10. UNIX for Dummies Questions & Answers

Delete logs every 3 hours

Hi, I want to setup a cronjob that will delete logs every 2 hours. I have script that delete logs per day. but logging is too big and i want to run a conjob that will delete every 2 hours. this is my current command but it deletes on a per day basis. find . -name "*.log*" -o -name... (3 Replies)
Discussion started by: tungaw2004
3 Replies
Login or Register to Ask a Question