- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A shell problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 01:25 AM
11-03-2001 01:25 AM
I have a simple shell script of the form:
for var in list
do
--- write something into a file say TMP -----
--- read line by line and
------ for each line
do some actions.
The problem is the cotrol breaks from the inner loop even w/o completely reading the file .
It looks to be a problem with the shell buffer or something else?
The original script is below (MKDIR and CREATELINK are small shell script for creating dirs and links in clearcase environment)
I have highlighted the problem part in blue.
Can any one pinpoint the actaul cause for the problem?
==================================================================================================
set -xv
PRODUCT=$1
FLAVOR=$3
RELEASE=$2
BE_ROOT=/ha/be_sam
INFILE=$BE_ROOT/manifest.$PRODUCT.$FLAVOR
MAPPING=$HOME/MAPPING
TMP=$HOME/input$$
TARGET=$BE_ROOT/"$RELEASE"_$FLAVOR/
CREATEABELOG=$HOME/log/CREATEABELOG$$
CREATEABEERR=$HOME/log/CREATEABEERR$$
MKDIR=$HOME/bin/MKDIR
CREATELINK=$HOME/bin/CREATELINK
if [ ! -f $CREATEABELOG ]
then
touch $CREATEABELOG
else
rm $CREATEABELOG
touch $CREATEABELOG
fi
if [ ! -f $CREATEABEERR ]
then
touch $CREATEABEERR
else
rm $CREATEABEERR
touch $CREATEABEERR
fi
if [ ! -f $CREATEABELOG -o ! -f $CREATEABEERR ]
then
echo "$CREATEABELOG OR $CREATEABEERR COULD NOT BE CREATED"
exit 1
fi
if [ ! -f $MAPPING ]
then
echo "$MAPPING DOES NOT EXIST"
exit 1
fi
if [ ! -r $INFILE ]
then
echo "$INFILE DOES NOT EXIST OR IS NOT READABLE"
exit 1
fi
for SRC in `grep "augmentation level" $INFILE |awk '{print $1}'`
do
sed -n '/'$SRC' augmentation level/,/augmentation level/p' $INFILE | sed '/augmentation level/d' |sed '/rule/d' >$TMP
ROOTSRCDIR=`grep $SRC $MAPPING | cut -f2`
echo "=============================="
cat $TMP | while read LINE
do
FILE=`echo $LINE|awk '{ print $3 }'`
DIR=`dirname $FILE`
echo "LINE ....$LINE"
if [ ! -d $TARGET/$DIR ]
then
$MKDIR $TARGET/$DIR $CREATEABELOG $CREATEABEERR
fi
if [ -f $ROOTSRCDIR/$FILE ]
then
RESULT=`cksum $ROOTSRCDIR/$FILE | awk '{ print $1 $2 }'`
LINE12=`echo $LINE | awk '{ print $1 $2 }'`
if [ "$RESULT" = "$LINE12" ]
then
$CREATELINK $ROOTSRCDIR/$FILE $TARGET/$FILE $CREATEABELOG $CREATEABEERR
else
echo "$ROOTSRCDIR/$FILE has checksum problems" >> $CREATEABEERR
fi
else
echo "$ROOTSRCDIR/$FILE does not exist" >> $CREATEABEERR
fi
done
done
=======================================================================================
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 01:26 AM
11-03-2001 01:26 AM
Re: A shell problem
cat $TMP | while read LINE
....
Thanks,
Jayesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 04:49 AM
11-03-2001 04:49 AM
Re: A shell problem
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 04:56 AM
11-03-2001 04:56 AM
Re: A shell problem
It does read LINE,
but i do not know it breaks all of a sudden to the outer loop.
I do not understand the reason.Well,Is it easy to write the same in perl?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 06:45 AM
11-03-2001 06:45 AM
Re: A shell problem
I think the essential problem is that your outer 'do' loop is writing to the TMP file, while the inner loop is attempting to read the same file. I suggest that you rearrange your code into two indepenedent passes -- the first to write to the file; the second to read the updated information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 06:53 AM
11-03-2001 06:53 AM
Re: A shell problem
live free or die
harry
#!/usr/bin/perl???? you need to put the path to perl here
$PRODUCT=$1;
$FLAVOR=$3;
$RELEASE=$2;
$BE_ROOT=/ha/be_sam;
$INFILE=$BE_ROOT/manifest.$PRODUCT.$FLAVOR;
$MAPPING=$HOME/MAPPING;
$TARGET=$BE_ROOT/"$RELEASE"_$"FLAVOR/";
$CREATEABELOG=$HOME/log/CREATEABELOG$$;
$CREATEABEERR=$HOME/log/CREATEABEERR$$;
$MKDIR=$HOME/bin/MKDIR;
$CREATELINK=$HOME/bin/CREATELINK;
eval `cat /dev/null >$CREATEABELOG` or die "Could not null $CREATEABELOG";
open (ABELOG,">>$CREATEABELOG") || die "Could not open $CREATEABELOG for appending";
eval `cat /dev/null >$CREATEABEERR` or die "Could not null $CREATEABEERR";
open (ABEERR,">>$CREATEABEERR") || die "Could not open $CREATEABEERR for appending";
open (FILEHANDLE, $MAPPING ) || die "MAPPING DOES NOT EXIST";
open (FILEHANDLE, $INFILE ) || die "INFILE DOES NOT EXIST OR IS NOT READABLE";
open (SRClist, `grep "augmentation level" $INFILE |awk '{print $1}'|` ) || die "No data to process";
while ($src=
chop($SRC);
open (TMP, `sed -n '/'$SRC' augmentation level/,/augmentation level/p' $INFILE | sed '/augmentation level/d' |sed '/rule/d'|` ) || die "No data to process";
$ROOTSRCDIR=`grep $SRC $MAPPING | cut -f2`;
print "==============================\n";
while ($LINE =
chop($LINE);
$FILE=`echo $LINE|awk '{ print $3 }'`;
$DIR=`dirname $FILE`;
print "LINE ....$LINE\n";
if (! -d "$TARGET/$DIR" ) {
`$MKDIR $TARGET/$DIR $CREATEABELOG $CREATEABEERR`;
}
if ( -f "$ROOTSRCDIR/$FILE" ) {
$RESULT=`cksum $ROOTSRCDIR/$FILE | awk '{ print $1 $2 }'`;
$LINE12=`echo $LINE | awk '{ print $1 $2 }'`;
if ( $RESULT eq $LINE12 ) {
eval `$CREATELINK $ROOTSRCDIR/$FILE $TARGET/$FILE $CREATEABELOG $CREATEABEERR` or die "Could not create link";
} else {
print ABEERR "$ROOTSRCDIR/$FILE has checksum problems\n";
}
} else {
print ABEERR "$ROOTSRCDIR/$FILE does not exist\n";
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 07:50 AM
11-03-2001 07:50 AM
Re: A shell problem
But the problem remains.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 07:51 AM
11-03-2001 07:51 AM
Re: A shell problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 07:57 AM
11-03-2001 07:57 AM
Re: A shell problem
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2001 09:05 AM