perl script - adding restart logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script - adding restart logic
# 1  
Old 06-18-2008
perl script - adding restart logic

Hi all
I have written a perl script which looks at one file and if new entry is made to that file then it runs some scripts depending upon the entry made to file( used File::Tail module ) . This script is running as “root” in nohup mode. Script works fine but I want to add restart logic.
If scripts exits in between consider on line 15 and by the time I restart the script 5 more entries are added to file so 15-20 entries are never processed I don't want that. I am thinking of writing last processed time in one file but I am not getting how can I process those 5 lines how can start tailing of file from line 15 and not 20. Or should I create dummy file?
All suggestions are welcome.
# 2  
Old 06-18-2008
IF the file has a unqiue line identifier - for example: like a timestamp, everytime your code processes the line, write the unqiue indentifier to a file or a db table. Otherwise use the linenumber in the file.

When you restart, search forward to find the last unique identifier you processed, since you can recover it from the file or table. Anything in the logfile past that point is new.
# 3  
Old 06-18-2008
I could have sworn File::Tail already has some function/method to handle this type of scenario.
# 4  
Old 07-08-2008
Hi... Wonder if you solved this...

I was thinking keep a line counter around in the script and store it's last value in a separate file every time you process a line. If your script exits, when you re-start get the last line count (from your external file or DB wher ever you put it) and do a seek() to the line + 1, etc...
# 5  
Old 07-08-2008
hi quine thanx for reply ...

ya i wrote that logic abt 2 weeks back only
i used the same logic as u suggested keep last entry in one file when script runs ( fresh start ) then compare last entry on main file & restart file if not same then get all lines from main file in another temp file process them and once all that finished do compare again ... every time i process file i update entry in restart file.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Restart logic in script

I have a question regarding the restart logic in scripts. I have a script named "JOB1" which has 5 steps and every step has a program. Suppose my script fails at 4th step and the first 3 steps have completed successfully. I want to start my script from 4th step directly without doing any change... (1 Reply)
Discussion started by: champ2108
1 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

Perl scripts: requesting for logic explanation

Hi, balajesuri and durden_tyler, I have found your perl script for the thread https://www.unix.com/shell-programming-scripting/176370-perl-script-help-me-extracting-string.html, but find it difficult to understand the syntax. Could you or any forum members kindly shed some light on the logic... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

Shell/Perl logic for loop

Hi, I have a requirement as follows. Have 3 files. Need to match up the data in each one of them and sum up the data by a field and display it. example given below. File 1 : Name, Emp id File 2 : Empid, Subject, File 3 : Subject, Score, Class Match Emp id in File 1 and File 2 and then... (7 Replies)
Discussion started by: preethgideon
7 Replies

5. Shell Programming and Scripting

Restart Logic for a Korn Shell Master Script

Hello All, I was wondering if someone can help me to develop restart logic for a Korn Shell program (a master script) that I am developing. The program is design to invoke a series of child processes (Korn Shell Scripts) whose function is to create a series of load files on a specified mount... (0 Replies)
Discussion started by: jonesdk5
0 Replies

6. Shell Programming and Scripting

restart logic in a script

Hi I have a script as follows Function func0 <Set of validations done> Function Func1 <Set of commands and some of the variables set> Function Func2 <Set of commands and some of the varibales set> Function Func3 <Call a job(It is a datastage job which is called> Main job Call func0... (2 Replies)
Discussion started by: dnat
2 Replies

7. Shell Programming and Scripting

Shell or PERL Logic

Hello All, Currently i am working on a logic in PERL scripting ... But i am sort of stuck up, can any one please help. Here goes. 1. Search for a pattern in a file 2. If the pattern matched lets say 10 lines 2.1 Reterive the first line and check for another pattern 2.1.1 if... (1 Reply)
Discussion started by: maxmave
1 Replies
Login or Register to Ask a Question