log monitoring continously and executing commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting log monitoring continously and executing commands
# 1  
Old 03-08-2011
log monitoring continously and executing commands

Hi
I want a script which continously searches for a work "MAX xonnections reached" in log file . As soon as it sees the message it needs to do series of steps
1) execute netstat command and redirect output to a file in /tmp
2) again continue monitoring the log file .
this job should run until we kill the process of script
plesae suggest asap.
# 2  
Old 03-09-2011
Interview or Homework?
# 3  
Old 03-09-2011
Could this help you ?
Code:
#!/usr/bin/perl
use strict;

my ($pos,$file_name_cur_date);
while (1){
        open(FH,"<","inputfile") or die "FAIL:- $!\n";
        if (defined ($pos)) { seek FH,$pos,0;}
        while(<FH>){
                if(/MAX connections reached/) {
                $file_name_cur_date="/tmp/netstat_".`date '+%d%m%Y%H%M%S'`;
                `netstat > $file_name_cur_date`;
                 sleep 5
                }
        }
        $pos=tell FH;
        close(FH);
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing MQ commands in Perl

If you want to capture the output of any command, we then will be writing the system command in `` or qx. `` an qx works fine with all linux and windows system commands. But when I execute the below code.. it is displaying the output on the screen directly instead of storing to variable ... (3 Replies)
Discussion started by: giridhar276
3 Replies

2. Shell Programming and Scripting

Executing commands sequentially

Hello. I am new in shell script. Could anyone help me? I have un shell script. I need each command in it be sequentielly, when the first command ends the second starts. When the second ends et third starts, and so on Thanks in adavance (1 Reply)
Discussion started by: nurinolo
1 Replies

3. Shell Programming and Scripting

Executing commands

I need to execute a command to run my script several times with varying parameters perl ex.pl -b 130198 -e 130884 -c plot plot.txt 1_plot.txt perl ex.pl -b 1345 -e 1308 -c plot plot.txt 2_plot.txt perl ex.pl -b 1345567 -e 130898 -c plot plot.txt 3_plot.txt . . . 100's of excutions ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

4. Shell Programming and Scripting

Executing many commands at once

Hi, I want to run these two commands one after the other. awk 'BEGIN {OFS="\t"} {print $2}' sort -u rather than typing awk 'BEGIN {OFS="\t"} {print $2}' file1 > file2, then sort -u file2 > file3. Is it possible to run both commands on file1 then get output file3? Its kinda hard for... (5 Replies)
Discussion started by: kylle345
5 Replies

5. Red Hat

How commands are executing ?

Hi Folks, I have a small doubt, the binary commands under /bin and /sbin as well as other path binary files, if you peek deep into that, you can find the difference in the way of normal perl programming and some commands will be like binary files. how are the commands executing like the... (3 Replies)
Discussion started by: gsiva
3 Replies

6. Shell Programming and Scripting

Continously checking folder and executing files

Hello All, I want to make a script which continously checks one folder all the time that is there is any file in it or not, and if it found any file in it than execute that file with the following command. apxrcv -text < filename > outputfile Actually my requirement is that i will put... (4 Replies)
Discussion started by: wakhan
4 Replies

7. Shell Programming and Scripting

Monitoring a directory for new files with .xx and executing command if found

Hi Guys. I am a complete shell scripting newbie with some syntax and commands understanding. I'm more of a win admin. With that said: I need to write a shell script to monitor a directory '/Mon_Dir' for new occurrences of files with .xx extension. Once a new file is detected in the directory, a... (4 Replies)
Discussion started by: krkan
4 Replies

8. UNIX for Dummies Questions & Answers

Executing commands after I log off

Hi, guys ! I have at home a simple network. I have a server that shares the internet connection to my computer and another another computer which is located in another room. When I want to download something, I'd like to download directly on the server, without letting my computer on. The server... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies

9. UNIX for Dummies Questions & Answers

FTP - Executing Commands

I have written a script to ftp a file from Unix to an NT machine to authenticate ftp login I have added the information into the .netrc file when logged in using ftp the commands are not executed. Does anybody know how to make the command execute once username and password have been provided using... (2 Replies)
Discussion started by: hesmas
2 Replies

10. UNIX for Dummies Questions & Answers

Executing commands with xargs

I have a SQL script that requires values from the environment in order to execute. I found a way to get the desired results but my process is a little choppy. Any suggestions on how to clean this up would be greatly appreciated. SQL Script ------------- select a, b, c from d where a =... (1 Reply)
Discussion started by: bmopal
1 Replies
Login or Register to Ask a Question