Skip to main content

Thread: Another Bash Script


all,

still have not solve mount issues thread at:

http://ubuntuforums.org/showthread.php?t=1757014

have more pressing problem right now. have client huge web implementation, of on 5,000 web pages, due bad advice on seo, have search these files specific strings. add problem isp has not , not install "locate" fuction on server, having use "find" command job done.

anyway have use find catalog files, use cat grep find string, i'm looking for. here i'm @ code:
calling script:
code:
#! /bin/bash        bash str-search.sh /home/mypath "php*, htm*, tpl" $hostname
and code calling is:
code:
#! /bin/bash        vpath=$1;   # file path process    vfext=$2;   # file extension(s) process    vtext=$3;   # string find in files        echo "p==> $vpath";    echo "e==> $vfext";    echo "t==> $vtext";      # go path/directory       if [ -z "$vpath" ]            # parameter #1 0 length?               cd /home/my_def_path;       else         cd $vpath;       fi      # parse ext var array    fargs = explode($vfext);        file in `find $vpath/. -name "*.php*"`           result=`grep $vtext $file`;        if [[ $? -eq 0 ]]                   echo $file $result $linenum;        fi    done        file in `find $vpath/. -name "*.htm*"`           result=`grep $findstr $file`;        if [[ $? -eq 0 ]]                   echo $file $result $linenum;        fi    done        file in `find $vpath/. -name "*.tpl*"`           result=`grep $findstr $file`;        if [[ $? -eq 0 ]]                   echo $file $result $linenum;        fi    done      filecontent=( `cat "logfile" `)        t in "${filecontent[@]}"       echo $t    done
i have not dome array processing in bash before @ line 20 of code need know way process ext var/array allow loop instead of separate hard coded calls have exts.

appreciate help!

thanks!

omr

all,

latest code promises improvement:
code:
#! /bin/bash        vpath=$1;   # file path process    vfext=$2;   # file extension(s) process    vtext=$3;   # string find in files        echo "p==> $vpath";    echo "e==> $vfext";    echo "t==> $vtext";      # go path/directory       if [ -z "$vpath" ]            # parameter #1 0 length?               cd /home/my-def-path;       else         cd $vpath;       fi      # parse ext var array    nargs = ${vfext[@]};      (( i=0; i<${nargs}; i++ ));            arelm = ${vfext[$i]};        file in `find $vpath/. -name "*.$arelm*"`                            result=`grep $vtext $file`;                if [[ $result -eq 0 ]]                                     echo $file $result $linenum;                fi             done       done        filecontent=( `cat "logfile" `)        t in "${filecontent[@]}"       echo $t    done
just got figure out "cat" statements go , how pipe output file.

thanks!

omr


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [ubuntu] Another Bash Script


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support