|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 01:10 PM |
| Awk print to file problem | TasosARISFC | Shell Programming and Scripting | 9 | 03-06-2011 04:44 PM |
| Print Problem in UNIX. Need to know the option to specify the print paper size | ukarthik | HP-UX | 1 | 06-07-2007 09:35 AM |
| Print problem | Vijay11 | AIX | 1 | 09-14-2005 03:03 AM |
| Print Problem | Mark Duncan | UNIX for Dummies Questions & Answers | 2 | 10-11-2001 08:08 AM |
|
|