linkdollar.sh

 

#/usr/bin/ksh
### linkdollar.sh
###
### Usage:
###
###    linkdollar.sh linkdir file.html phrase
###
 
 
 
 if [ "$3" = "" ]
 then
    echo "Usage: $0 linkdir filename phrase"
    exit 1
 fi
 
 
 linkdir=$1
 file=$2
 key1=$3
 key2=$4
 key3=$5
 key4=$6
 key5=$7
 key6=$8
 key7=$9
 
 
 path=`pwd | sed "s,/var/www,," | sed "s,/,/,g"`
 
 
 phrase=$key1
 
 if [ "$key2" != "" ]
 then
    phrase="${key1} ${key2}" 
 fi
 
 if [ "$key3" != "" ]
 then
    phrase="${key1} ${key2} ${key3}"
 fi
 
 if [ "$key4" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4}"
 fi
 
 if [ "$key5" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5}"
 fi
 
 if [ "$key6" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6}"
 fi
 
 if [ "$key7" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} "
 fi
 
 if [ "$key8" != "" ]
 then
    phrase="${key1} ${key2} ${key3} ${key4} ${key5} ${key6} ${key7} ${key8}  "
 fi
 
echo "Looking for $grep"
 
for i in `find $linkdir -name \*.htm\* -print | egrep -v "/$file" `
 do



     ib=`basename $i`

     if [ "$ib" = "$file" ]
     then
         echo "$ib = $file, skipping"
         continue
     fi 
 
     #if `egrep -w "$grep" $i >/dev/null 2>/dev/null`
     if `egrep -l "$grep" $i >/dev/null 2>/dev/null`
     then
 

         xfile=`echo $file | sed "s/\////g"`
     
         p="http://www.setgetweb.com${path}/${xfile}"
 
         echo " "
         echo "Creating link in:"
         echo "    $i"
         echo " "
         echo "using the phrase: "
         echo "    \$$grep"

         echo " "
 
         sed "s/\$$grep/\$<a href=\"$p\">$phrase<\/a>/"  $i | \
         sed "s///\//g"  > tmp.$$
         mv -f tmp.$$ $i


     fi


 
 done