Wants alternate to the Sleep option??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wants alternate to the Sleep option??
# 8  
Old 02-20-2009
Power

BRO...wait $! is probably not the right solution and it's not working also for this particular script

What I need is instead of sleep I want few lines of code which will check for the PID in the last line(tail -1) of current_date.log file in /abc/xyz directory....and check if the same PID count is 2 then it should execute the next job....

(Ex:- more Jan_12.log
Mon Jan 12 01:43:48 Program: saimptlogi: PID=12409: Started by rms
Mon Jan 12 01:45:50 Program: saimptlogi: PID=12409: Thread 1 - Terminated Successfully )

Please have a thorough look at my initial script and help me....I need these help badly...
# 9  
Old 02-21-2009
Maybe this will help. Run tail on the log file, use perl to scan the output. When perl sees two lines with the same PID, it executes the command provided to perl on the rest of the command line.
Code:
tail -2f current_date.log | perl -ne '/PID=([0-9]+):/ && { $pid{$1}++; if ($pid{$1} >= 2) { exec(@ARGV); }' next-job arg1 arg2 ...

# 10  
Old 02-26-2009
Lightbulb

So instead of sleep 140 in the above mentioned script.....can I put it like this..will it work?:

cd $MMHOME/log
while
do
more $(ls -ltr|tail -1|cut -c 55-70)|grep "saimptlogi"|tail -2f|perl -ne '/PID=([0-9]+):/ && { $pid{$1}++; if ($pid{$1} >= 2)'
sleep 60
done

Last edited by satyajit007; 02-26-2009 at 05:11 AM..
# 11  
Old 02-26-2009
Um, no, because the tail won't exit with the -f option, and the PERL script won't exit by itself. (Also, you don't need "more" here). This is more what you're looking for
Code:
cd $MMHOME/log
logfile=$(ls -ltr|tail -1|cut -c 55-70)
if ! tail -2f $logfile |
        perl -ne '/saimptlogi/ && /PID=([0-9]+):/ && do { $pid{$1}++; exit 1 if ($pid{$1} >= 2) }'
then
        echo "Started"
fi

Note, it does not exit or return until the process has started!
If it's not working for you, try increasing the tail -2f to tail -4f or something. That allows more lines of backlog to be seen. But it also means you might "catch" prior running instances.

Last edited by otheus; 02-26-2009 at 07:48 AM.. Reason: bad syntax
# 12  
Old 02-26-2009
syntax error

Sir....It is giving the following error.....

savouch_75002_20090210_20090226160640.out/appdb/product/agent/tmp/AAAjzaWJcsyntax error at -e line 1, near "; exit"
Execution of -e aborted due to compilation errors.

Started

PL/SQL procedure successfully completed.

/appdb/product/batch/rms/pos/RTLOG_GCN1.TXT
2
./saimptlogi_batch.sh[17]: ./saimptlogi: not found
syntax error at -e line 1, near "; exit"
Execution of -e aborted due to compilation errors.
Started

Also i think we should close { $pid{$1}++; exit 1 if ($pid{$1} >= 2)' .....with a } bracket ???

Last edited by satyajit007; 02-26-2009 at 06:51 AM..
# 13  
Old 02-26-2009
Right, I was missing the end bracket. That accounts for the error.
# 14  
Old 02-26-2009
Lightbulb

Quote:
Originally Posted by otheus
Right, I was missing the end bracket. That accounts for the error.
Thanks...I will test it and inform you abt the result....

Last edited by satyajit007; 02-27-2009 at 12:54 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Unrecognized option: sparc-sun-Solaris2.10/bin/as: unrecognized option `-m32'

Hi, I installed some packages required by an app built with python. But when I try python setup.py install, I get the following error: /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/../../../../sparc-sun-solaris2.10/bin/as: unrecognized option `-m32' Could anyone tell me what's wrong... (4 Replies)
Discussion started by: Kimkun
4 Replies

2. HP-UX

Alternate for wget

Hi, Whats the alternate for wget in HP-UX ? (4 Replies)
Discussion started by: mohtashims
4 Replies

3. UNIX for Dummies Questions & Answers

Alternate for pwdx in HPUX

I need alternate command as pwdx does not work on HP-UX mymachine B.11.31 U ia64 3223107173 unlimited-user license (6 Replies)
Discussion started by: mohtashims
6 Replies

4. Shell Programming and Scripting

Alternate to SLEEP for EXPECT within BASH script?

Fairly new to the System Admin world, and this is my first post here, hoping to get some clarification. I am using a BASH script to automate some Logfile Archiving (into .tars). The actual logfiles are accessed through an SSH, so I have used the following EXPECT sub-script within my main BASH... (8 Replies)
Discussion started by: Goatfarmer03
8 Replies

5. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

6. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

7. Shell Programming and Scripting

alternate lines

Hi, I'm new to Unix. I want to read the all the lines from a text file and write the alternate lines into another file. Please give me a shell script solution. file1 ----- one two three four five six seven newfile(it should contain the alternate lines from the file1) ------- one... (6 Replies)
Discussion started by: pstanand
6 Replies

8. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

9. Shell Programming and Scripting

Alternate way for echo.

Hi, Is there any other command echo does. if I am doing this operation for each line in my file. So its taking very long time to process more than 1000 records. Is there any alternative way to write the above if statement (5 Replies)
Discussion started by: senthil_is
5 Replies
Login or Register to Ask a Question