hi dive - excellent alternative solution! the script worked great after that. the problem seemed to be with sed; the script produced some very strange results:
1) most files were truncated (i think sed has a memory limit or something..)
2) files were being copied & dropped in random folders
3) files were having their contents erased so the byte size was 0
here is the finished script
Code:
#!/bin/bash
# this script recursively inserts a line into the head of all files
# in the directory from where it was called
# it notes all files changed to output.txt
# it shows everything the script does in logs.txt
logs=/home/logs.txt
output=/home/output.txt
phead='<?php include("func.php");validateUser($_SERVER["PHP_SELF"]);?>'
for i in *
do
if [ -d "$i" ] # if * is a directory
then
echo "1) $PWD" >> $logs
cd "$i" # descend into the directory
for y in *
do
if echo "$y" | grep ".htm"
then
echo "2) modifying: $PWD/$y" >> $logs
echo $phead > temp
cat $y >> temp
mv -v temp "${y%.*}.php"
chmod 744 "${y%.*}.php"
rm -v $y
echo "$PWD/$y" >> $output #for testing
fi
if [ -d "$y" ] # if a directory, call self
then
echo "3) $PWD" >> $logs
cd "$y"
sh /home/c.sh; # call self (recursively)
cd ..
echo "4) going back up to: $PWD" >> $logs
fi
done
cd ..
fi
if echo "$i" | grep ".htm"
then
echo "5) modifying: $PWD/$i" >> $logs
echo $phead > temp
cat $i >> temp
mv -v temp "${i%.*}.php"
chmod 744 "${i%.*}.php"
rm -v $i
echo "$PWD/$i" >> $output #for testing
fi
done
it has one limitation - some of the files in these directories were made with Frontpage [puke] and thus have folder in the same directory named the same way but with the word "html" in them. for example the file "content.html" includes two files: ./_vti_cnf/content.html and ./_derived/content.html_sourcecontrol whatever the f those are, and they get changed by the script too.
for anyone that is intested i also found another way to check for the file extension:
Code:
for i in *;do
if [ ! -d "$i" ];then
ext=${i##*.}
echo '$i' is $i and it\'s extension is $ext
if [ $ext = htm ]; then
echo "$i ends with htm"
if
fi
done