Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 02-20-2009
Registered User
 

Join Date: Jan 2009
Posts: 18
Red face

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...
Sponsored Links
  #9 (permalink)  
Old 02-21-2009
otheus's Avatar
otheus otheus is offline Forum Advisor  
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,906
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 (permalink)  
Old 02-26-2009
Registered User
 

Join Date: Jan 2009
Posts: 18
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 (permalink)  
Old 02-26-2009
otheus's Avatar
otheus otheus is offline Forum Advisor  
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,906
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 (permalink)  
Old 02-26-2009
Registered User
 

Join Date: Jan 2009
Posts: 18
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 (permalink)  
Old 02-26-2009
otheus's Avatar
otheus otheus is offline Forum Advisor  
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,906
Right, I was missing the end bracket. That accounts for the error.
  #14 (permalink)  
Old 02-26-2009
Registered User
 

Join Date: Jan 2009
Posts: 18
Lightbulb

Quote:
Originally Posted by otheus View Post
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..
Sponsored Links
Closed Thread

Bookmarks

Tags
scripting, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
alternate to set -x in csh scripts sais Shell Programming and Scripting 3 10-12-2008 09:04 AM
alternate lines pstanand Shell Programming and Scripting 6 03-18-2008 11:14 PM
option followed by : taking next option if argument missing with getopts gurukottur Shell Programming and Scripting 2 03-17-2008 12:46 PM
Alternate way for echo. senthil_is Shell Programming and Scripting 5 03-05-2008 09:12 AM
Alternate command for cut Mohammed Shell Programming and Scripting 2 10-20-2006 08:42 AM



All times are GMT -4. The time now is 12:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0