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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probem reading lines from a file !!!

Status
Not open for further replies.

RJSHA1

Programmer
Apr 12, 2001
66
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
cd $LINE
find . -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


Thanks
Bob...





 
Try something like this:
Code:
#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 
#              ^ missing in your post
  echo &quot;$LINE&quot;; [ -d &quot;$LINE&quot; ] || continue
  cd &quot;$LINE&quot;  # I assume the path is not relative ...
  find . -mtime +$CMPDAY -exec gzip -9 {} \;  
done <$CTM_FILEDIR/filelist.txt >>$LOGFILE 2>&1
You can post the code that creates the filelist.txt ?


Hope This Help
PH.
 
Try something like this:
Code:
#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 
#              ^ missing in your post
  echo &quot;$LINE&quot;; [ -d &quot;$LINE&quot; ] || continue
  cd &quot;$LINE&quot;  # I assume the path is not relative ...
  find . -type f -mtime +$CMPDAY -exec gzip -9 {} \;  
done <$CTM_FILEDIR/filelist.txt >>$LOGFILE 2>&1
You can post the code that creates the filelist.txt ?


Hope This Help
PH.
 
Ok maybe you should look at it a different way for a moment:

Data in /tmp/list.txt =

/etc/httpd/conf/backup
/var/log/httpd
/var/log/weblogic


To read the contents of a file and perform some action on each line is a simple case of:

for ITEM in `cat /tmp/list.txt`; do ls -al $ITEM ; done

Ok so thats simple? or we can do part of what you want with:

for ITEM in `cat /tmp/list.txt`; do /usr/local/bin/gzip -9 $ITEM/*.bak ; done
or
for DIRECTORY in `cat /tmp/list.txt`; do find $DIRECTORY -mtime +7 -exec /usr/local/bin/gzip -9 {} \; ;done

Generating the list.txt depends on what you want to capture, but could be one of the following:

manual construction edit file by hand,
find <path> -type d -print > /tmp/list.txt



I hope that has helped you think about it a bit?

Oh! and you are not passing anything into LINE thats why its empty.

For the real experst take a look at forum822 Luck,
Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top