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:
and code calling is:code:#! /bin/bash bash str-search.sh /home/mypath "php*, htm*, tpl" $hostname
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.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
appreciate help!
thanks!
omr
all,
latest code promises improvement:just got figure out "cat" statements go , how pipe output file.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
thanks!
omr
Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [ubuntu] Another Bash Script
Ubuntu
Comments
Post a Comment