Script for monitoring logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for monitoring logs
# 1  
Old 07-17-2013
Script for monitoring logs

hi,
i'm using unix solaris 5.8. I have to write a shell script for monitoring logs. whenever the logs are not updated more than one hour an alert will be send to my mail. I'm new to Unix, so could anyone help me to find this.
# 2  
Old 07-17-2013
ls -l gives you the last modification time of the log.
date takes format modifiers that return the current time any way you want it.
So a comparison of the last modified time with the current time is possibe in a shell script.

Alternatively Perl offers a stat function and a time function, both of which use epoch time and so a comparison is easier, ie.

Code:
 perl -e  '@file_detais=stat($ARGV[0]);print "Not changed in the last hour\n" if ((time() - ($file_details[9] + (60 * 60))) > 0); '  my_file.tmp

# 3  
Old 07-17-2013
Script for monitoring logs

thanks for ur reply. Actually that comparision is the problem. The logs last updated time is like 10:30 but the system time is like 10:45:56, i can't able to find the difference. Could u pls help for this.
# 4  
Old 07-17-2013
Quote:
Originally Posted by Arasu
thanks for ur reply. Actually that comparision is the problem. The logs last updated time is like 10:30 but the system time is like 10:45:56, i can't able to find the difference. Could u pls help for this.
Check this thread. I wrote a script that basically does the same thing. If you have questions after going through the posts in that thread, do not hesitate to let me know and I'll be more than glad to help.
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. Red Hat

Profile.d script logs out

Hi, I included a command set -o vi & sudo -l user -c script in profile.d and /etc/profile. unfortunately the script has some command that logs me out every time I try to login from all users including root user. this is happening from GUI. can I login to prompt directly? or is there an... (7 Replies)
Discussion started by: ahmedwaseem2000
7 Replies

3. Shell Programming and Scripting

[Help] Script to monitor logs

Hello friends, as they are? First of all sorry for my poor English. I tell them what is my problem. I have the following script, which is basically what makes error search for a pattern within a folder containing logs. The script works fine, the problem is that whenever I find a pattern of new... (2 Replies)
Discussion started by: romanrsr
2 Replies

4. UNIX for Dummies Questions & Answers

Monitoring windows logs

is it possible to monitor log files that are on a windows server, from a linux/unix host? i'm thinking that the directory that the files are located in on windows can be be mounted on the linux host, and then a script or tool can just monitor the log as though it were local? any thing wrong... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

bash script logs

Hi, I have a bash script and I am run it manually. It starts, but actually is doing nothing, probably because of a wrong input parameter.....Is there a place /directory/file where I can see a log for the script? (1 Reply)
Discussion started by: apenkov
1 Replies

6. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

7. Shell Programming and Scripting

script for reading logs of a script running on other UNIX server

Hi, I have a script, running on some outside firwall server and it's log of success or failure is maintained in a file. I want to write a script which ftp that server and reads that file and checks the logs and if failure , I will send mail notification. Please let meknow if I am not... (1 Reply)
Discussion started by: vandana.parwani
1 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. Shell Programming and Scripting

script to move logs

Does anyone have a good script to move log files from a cron? There are a lot of logs, about 100 or more and they are constantly being written too. (7 Replies)
Discussion started by: photon
7 Replies

10. UNIX for Dummies Questions & Answers

Perl Scripting for monitoring logs

Hi, I am new to perl. I want to write a perl script to monitor logs. Where i want to monitor exceptions logged or any kind of error strings. I have a dir(On Solaris) with multiple log file which keeps rolling to .gz file after some time in that same dir. These logs files size keeps on... (1 Reply)
Discussion started by: solitare123
1 Replies
Login or Register to Ask a Question