Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probelm reading a line from a file - value always blank

Status
Not open for further replies.

RJSHA1

Programmer
Apr 12, 2001
66
0
0
GB
Hi there,
I'm trying to write a shell script where I create a file of directories that I want to compress. Then I loop round reading the file picking up the directory name and then doing a find with a gzip -9.
That's the theory anyway, what is happening is that the variable $LINE is ALWAYS blank and for the life of me I have no idea where I'm going wrong.
Does anyone have any ideas. I have tried also using a WHILE loop as well, but I get the same result. Below is the code I'm using.
Any suggestions anyone

sed '/^$/d' $CTM_FILEDIR/filelist.txt > /tmp/file_output.txt
mv /tmp/file_output.txt $CTM_FILEDIR/filelist.txt
rm -f /tmp/file_output.txt
echo "Generating Directory list" >> $LOGFILE 2>&1
while read LINE; do
echo $LINE
find $LINE -mtime +$CMPDAY -exec gzip -9 * {} \; >> $LOGFILE 2>&1
done < $CTM_FILEDIR/filelist.txt

The file I'm reading from is $CTM_FILEDIR/filelist.txt. It has no blank lines
I posted this in the General Unix forum and they suggested posting it here

Thanks
Bob...





 
which shell are you running this as?

a ksh, or bash (sh) ?
 
hmm ... strange.

Code:
#!/bin/ksh
find /home/jad/docs > filelist.txt
sed '/^$/d/' filelist.txt > /tmp/filelist.txt
mv -f /tmp/filelist.txt filelist.txt
while read LINE; do
echo $LINE
done < filelist.txt

works for me.

can you &quot;echo $CTM_FILEDIR/filelist.txt&quot; for me in the program just after the while statement(or somewhere else easily visible)? :)
 
Hi Jad,
The value of $CTM_FILEDIR/filelist.txt is echo /bx076a/ibct0004/ibctdbat/FILES/filelist.txt


This file contains the following values
/bx076a/ibct0004/ibctdbat/FTP/IN
/bx076a/ibct0004/ibctdbat/FTP/OUT
/bx076a/ibct0004/ibctdbat/FILES
 
is the file a Unix file, or a windows file? (i.e. does it have ^M's in it?)

does the 'echo $LINE' print _anything_ out?
does a 'wc -l $CTM_FILEDIR/filelist.txt' give the answer '3'?

i was checking the $CTM_FILEDIR thing just in case the file was $CTM_FILEDIR was set inside the program, or even overwritten somehow.

if you 'cat $CTM_FILEDIR/filelist.txt' inside your program does it write out the 3 lines from within it?
 
Hi Jad,
I have tried these thw wc -l returns 3 lines, and the cat does print the three lines as well. I have included the code that creates the file in case there is any thing dodgy with that :-

sqlplus -s rjsha1/password@database << EOF
set pagesize 0 feedback off verify off heading off echo off term off
spool $CTM_FILEDIR/filelist.txt
select val from system_parameter
where (name like '%FTP%' OR name like '%FILES%');
exit;
EOF

Then it goes into the next section

sed '/^$/d' $CTM_FILEDIR/filelist.txt > /tmp/file_output.txt
mv /tmp/file_output.txt $CTM_FILEDIR/filelist.txt
rm -f /tmp/file_output.txt
echo &quot;Generating Directory list&quot; >> $LOGFILE 2>&1
while read LINE; do
echo $LINE
find $LINE -mtime +$CMPDAY -exec gzip -9 * {} \; >> $LOGFILE 2>&1
done < $CTM_FILEDIR/filelist.txt



 
if the file has stuff in it then the first bit of code is working fine.

also i now know that the file was written on the same system as the ksh script so i know that the file won't have ^M's in it.

if you create a new script that just does:
Code:
#!/bin/ksh
while read LINE; do
echo $LINE
done < /bx076a/ibct0004/ibctdbat/FILES/filelist.txt

does it print out 3 lines?
 
Yes it does - now I am REALLY puzzled
 
ok ... lets build up to the larger object.

Code:
#!/bin/ksh
while read LINE; do
echo $LINE
done < $CTM_FILEDIR/filelist.txt
 
Try taking out >> $LOGFILE 2>&1 temporarily.

If that fixes it, then perhaps you need to use a third file descriptor for your while/read loop.

Annihilannic.
 
Hi guys

Bit of a break through - I commented out the SQL below ran the job pointing it to the file with the directories and IT WORKED !!!!! Below is the SQL I'm using can anyoone see anything wrong with it.

sqlplus -s rjsha1/password@database << EOF
set pagesize 0 feedback off verify off heading off echo off term off
spool $CTM_FILEDIR/filelist.txt
select val from system_parameter
where (name like '%FTP%' OR name like '%FILES%');
exit;
EOF

 
umm ... recently i wrote a script for someone else that got results from a file without spool.

but this should do:
Code:
#!/bin/ksh
echo &quot;rjsha1/password@database
set pagesize 0 feedback off verify off heading off echo off term off 
select val from system_parameter
    where (name like '%FTP%' OR name like '%FILES%');&quot; | sqlplus -s > $CTM_FILEDIR/filelist.txt

might work for you.

i didn't have all the 'feedback off' and 'sqlpus -s' stuff ... i used awk to trim it.
 
Hi Jad,
I have worked out a way to do it just as your mail arrived I created a .sql file and got the SHELL script to run it.

Thanks for all your help and patience

Regards

Bob Sharpe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top