Problem with print command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Problem with print command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-19-2006
rkumar28 rkumar28 is offline
Registered User
 
Join Date: Apr 2004
Last Activity: 21 November 2013, 1:07 PM EST
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with print command

Hi,
I have a small script and am having problem at one point. The script runs another script called Run_SQL.sh. All I am trying to do is if the return code from the script is not zero(0) then display some message(which is working fine) and if the return code is zero then run the SED command and run the print command below it.(see in RED BOLD below). My SED command executes fine but the print command sometime works and sometime does not work. Its sporadic. I know there is something very simple but am not able to figure out.

Any advice will be appreciated.

SQLDIR=$t_path
SQLLISTFILE=${t_path}/$SQLFILE

for SQLNAME in `cat $SQLLISTFILE`
do
SQLFILENAME=${SQLDIR}/${SQLNAME}
print "Running ${SQLNAME}"

Run_SQL.sh -f $SQLNAME
if [ $? -ne 0 ]
then
print "There is error in ${SQLNAME}. Check the file."
exit -1
else
var=`head -1 ${SQLLISTFILE}`
if [ "$var" == "$SQLNAME" ] then
sed '1d' ${SQLLISTFILE} | tee ${SQLLISTFILE} > /dev/null 2>&1 --->This command executes fine
print "${SQLNAME} ran sucessfully" --->This is where I am having problems. This command sometime displays and sometime does not displays text.
fi

fi

The command in bold above run sucessfully and sometime it does not show up at all even if the sed command is sucessful. I have to run this print command after the sed command only.

I will really appreciate any advice in this regard.
Sponsored Links
    #2  
Old 05-19-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 20 November 2014, 5:33 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 438 Times in 261 Posts
sed '1d' ${SQLLISTFILE} | tee ${SQLLISTFILE} > /dev/null 2>&1 --->This command executes fine.

Never write code soon after you look at one of M C Escher's drawings! You are reading from and writing to the same file from different sides of the same pipeline. OK, that almost makes sense... But the whole purpose of tee is to duplicate an I/O stream. You're keeping the duplicate and sending the original to /dev/null?! Umm...you wanted a fresh copy? Anyway you are going to get different results depending on a lot of factors. You need your sed process to completely read the file prior to the tee process opening the file. That might happen every now and then if the file is short enough.
Sponsored Links
    #3  
Old 05-19-2006
rkumar28 rkumar28 is offline
Registered User
 
Join Date: Apr 2004
Last Activity: 21 November 2013, 1:07 PM EST
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with the SED and TEE command

Hi,
I am sorry, I could not able to understand.
The file I am reading has bunch of sql filenames. Something like:

test1.sql
test2.sql
test3.sql
test4.sql

All I am trying to do is to delete the first line from the file on each iteration of the loop and refresh the file, so that the I can read the next sql filename.

Is there an example I can see in how to fix this.

Will appreciate any help on this.

Thanks
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Variable print problem prash_b Shell Programming and Scripting 4 01-31-2012 02:10 PM
Awk print to file problem TasosARISFC Shell Programming and Scripting 9 03-06-2011 05:44 PM
Print Problem in UNIX. Need to know the option to specify the print paper size ukarthik HP-UX 1 06-07-2007 10:35 AM
Print problem Vijay11 AIX 1 09-14-2005 04:03 AM
Print Problem Mark Duncan UNIX for Dummies Questions & Answers 2 10-11-2001 09:08 AM



All times are GMT -4. The time now is 12:27 PM.