This is a working program that I use to scour through lots of text for keywords. I put the keywords in the terms file, one line at a time (keywords or key phrases so they can have spaces). Each launches a recursive grep through whatever folder I need to look for those phrases. Best part is each search/grep is launched at same time (so you dont have to wait for one to finish before next begins)
This is based off: this article
The main script which has everything is look.sh (it contains the other scripts in it, they are just commented away for redundancy). It needs terms file with it (which you edit to include your terms). The other helper scripts are given as well (also as comments in look.sh)
look.sh <folder or file to search thru> that launches the script which makes the result files
Each result file looks like this _allSS_<term looked for>_<folder or file name given>.txt – you get as many result files as lines in terms that had valid terms.
Valid terms files are like:
term1
term2
term3
this is a phrase1 that has term4
phrase2 has a space as well
Then use any of the 3 monitoring scripts to monitor progress:
./monitor1-tail.sh – this shows the processes and also the last few lines of each result file (live as terms/phrases are being found)
./monitor2-lines.sh – this shows the processes and also the number of lines found in each result file (number of times each term was found, also live info)
./monitor3-processes.sh – this just shows the processes information that you get in monitor1 and monitor2 scripts (also it has system load and memory)
When your done you can concat all of your results to one file with ./together.sh
Move them to a folder (that will be made) – simple mkdir and mv script: ./move.sh <folder name>
Lets say you launched a whole group of grep commands and they are making result files already, need to clean up? run ./cleanup.sh
./print.script just outputs what you see below (completely optional) – it formats output with seperators and gives statistics about each file (word count, line count, etc…)
./backup.script is my own script that I run after I modify any of the source code – makes it easy to bundle everything up
==================================================
NOTE: look.sh program below has every script. its the main script, and it has all of the optional scripts commented out (for redundancy)
NOTE: added smartlook.sh (and nice and high priority variation of it) that runs X number of term searchs per at a time, then when done with those terms it moves on to the next X terms, until its done. Default is 10 terms at a time (10 is the default in smartlook.sh if number of terms per job is not specified)
==================================================
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
TERMSEARCH SOURCE CODE ####################### ####################### SOURCE CODE PRINTED USING print.script ON Wed Jan 22 18:57:11 PST 2014 Printing Code From the following files: cleanup.sh extract.sh look.sh monitor1-tail.sh monitor2a-justlines.sh monitor2b-totallines.sh monitor2-lines.sh monitor3-processes.sh move.sh nicelook-highpriority.sh nicelook.sh renice-high-priority.sh renice-normal.sh renice.sh smartlook-nice.sh smartlook-priority.sh smartlook.sh together.sh terms backup.script print.script *************************************************** *************************************************** SOURCE CODE OF FILE: cleanup.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:11 PST 2014 # of lines: 8 cleanup.sh # of bytes: 127 cleanup.sh # of chars: 127 cleanup.sh # of words: 20 cleanup.sh Longer line length: 23 cleanup.sh *************************************************** *************************************************** #!/bin/bash # last update: 1/3/2014 killall -9 grep rm -rf _all* # smartlook addition rm -rf terms-main-* rm -rf terms-work-* *************************************************** *************************************************** SOURCE CODE OF FILE: look.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 227 look.sh # of bytes: 10725 look.sh # of chars: 10725 look.sh # of words: 1767 look.sh Longer line length: 239 look.sh *************************************************** *************************************************** #!/bin/bash # last update 1/9/2014 # as per: http://www.infotinks.com/linux---grep-for-words-at-the-same-time # make sure to have a terms file called "terms" in the a directory before, 1 above, the directory you want to search - just like in this layout # /some/path/search/this/<everything here> # /some/path/search/look.sh - look.sh will look for the keywords listed in the "terms" file and only thru everything inside the folder "this" (/some/path/search/this/) # note the folder that needs to be specified has to not search thru the current working directory, so either search something 1 level deep from the current working directory, or some other branch in the filesystem tree # the search location is specified with the variabler RELDIR1, in the above example I would set RELDIR1="this" or RELDIR1="/some/path/search/this" - note i didnt put the slash / at end (its optional) # also note it can be relative or absolute path # in program below (the runnable part not commented out - aka the main part of the look program) the only part that is supposed to be edited (again thats the RELDIR1 variable)... # is set to a folder that I have been looking through 12-11-2013, thats the folders actual relative path. # It sits right next to the look.sh and terms file (so terms file and look.sh and results files and the serach directory are all in the same folder # the folder that they are all in doesnt matter - just like the part /some/path/search/ doesnt matter in the whole example - unless of course I gave the full path to RELDIR1). Just like in this example # /some/path/search/terms - note term file has keyword per line (no spaces per keyword, also realize that search is case insensitive) # /some/path/search/<results go here> # /some/path/search/monitor1-tail.sh - optional used to just monitor the long look.sh operation - shows the end of each result file on the go (as terms are being searched thru) # /some/path/search/monitor2-lines.sh - optional used to just monitor the long look.sh operation - shows the line count in each result file on the go # /some/path/search/monitor3-processes.sh - optional used to just monitor the long look.sh operation - just shows the processes and memory load (this info included in both of the above monitor scripts) # /some/path/search/cleanup.sh - optional, cleans (kills all grep commands - even ones not started by look.sh, also deletes all files that start with _all aka the result files) - good for starting fresh if messed something up # /some/path/search/together.sh - optional, concats all _all files in current directory - only run once as the file will grow exponentially everytime its run - so make sure a cleanup is run first - it still keeps originals # /some/path/search/move.sh - optional, this moves all of the results (all files with _all*) and copies terms file into a new directory (directory is made as well) # if you do this alot, i recommend doing the runs like this: edit terms, run clean up, run look, run monitor (immediately after or slightly after look script), then run the together script if you want it all together, then the move script. # you will notice nice and priority scripts: # ./nicelook-highpriority.sh <path>: runs look and all greps with nice of -19 so high priority good for short ops # ./nicelook.sh <path>: runs look and all grep with nice of 19 so low priority good for long ops # ./renice-high-priority.sh: if job already running can change prioritys to high if taking too long (note might impact cpu alot) # ./renice-normal.sh: changes all jobs to nice 0 (as if was run without nice or prioty so its like running app with just ./look.sh) # ./renice.sh: if job already running can change prioritys to super low (Aka nice) (good for long ops) ################################ # THE LOOK PROGRAM # # # # - the heart of the program # # # # # ################################ # # check if argument is there # if not show usage # check if argument is a directory or a file # if not show usage # # usage function usage123 () { ME123=`basename $0` echo "termsearch - by kostia - 2014" echo "Your using ./look.sh - for you it has the name of ./$ME123" echo "Usage:" echo "./$ME123 <directory or file to look thru>" echo "RESULTS: It will output files with name _allSS_<term>_<filename or directory given>" echo "REQUIREMENT: The terms it will look thru are listed SINGLE LINE at a time in a \'terms\' file that sits in the same folder as this file" echo "NOTE: each term needs to be seperated with a new line" echo "--DO NOT HAVE SPACES LIKE term1 term2 term3--" echo "Example of terms file:" echo "# cat terms" echo "term1" echo "term2" echo "* After running this, all search tasks - ran with grep - will be in the background" echo "* You can monitor your operation with MONITOR1 or MONITOR2 script" echo "* You can clean up everything with the CLEAN UP script - stops all grep operations and deletes all result files" echo "* You can concat all of the results together into 1 file - still keeping the originals - into one file with TOGETHER script" echo "* Finally you can move all of your results and together file - if you made one - into a folder using the move script" exit 1 } # main code if [ $# -eq 0 ] # 0 args then usage123 fi if [ $# -gt 1 ] # more then 1 arg then usage123 fi if [ -z "$1" ] # no argument in first arg then usage123 fi if [ -d "$1" ] ; then # if directory echo "Will look thru DIRECTORY: $1" else if [ -f "$1" ] ; then echo "Will look thru FILE: $1" else usage123 fi fi if [ -f "terms" ] ; then logger "termsearch thru $RELDIR1 for `wc -l terms` term[s]" else echo "ERROR: \'terms\' file is missing - it has to be in this directory and nowhere else" echo "More info on terms below" echo "---" usage123 fi # cant have file names with /, or else thats a directory - this doesnt affect filenames DIR123=${1%/} # change / to - for filename FILESUF123=`echo ${DIR123} | tr / -` echo "**** the file suf is kostia__${FILESUF123}__kostia ****" # IFS controls for loop new line char usually its space, but for now its new line # This way terms can have spaces in each line SAVEIFS=$IFS IFS=$(echo -en "\n\b") RELDIR1=${DIR123}; for i in `cat terms`; do echo "======================="; date; echo "Looking for: ${i}"; echo "======================="; TERM4FILE=`echo -n ${i} | tr ' ' -` (time (grep -nir ${i} ${RELDIR1}) >& _allSS_${TERM4FILE}_${FILESUF123}.txt &); echo "----------------------"; echo "Started PID: $!"; (ps awfuxx | egrep 'grep|USER' | nl;); echo; done; echo "##############################"; echo "FINAL JOBS:"; (ps awfuxx | egrep 'grep|USER' | nl;); echo echo "Looking for `wc -l terms` at the same time!" IFS=$SAVEIFS exit 0 # the monitor scripts # the are below # the clean up script # cleanup.sh (copy whole section to new file and remove only the first hash mark) ##!/bin/bash #killall -9 grep #rm -rf _all* # the put together script - puts all results together to 1 file # together.sh (copy whole section to new file and remove only the first has mark) ##!/bin/bash #DST1="_allTOGETHER_.txt"; for i in `ls | grep _allSS`; do echo "CONCATTING FILE: $i >> $DST1"; echo -e "TERM: $i\n###################" >> $DST1; cat $i >> $DST1; echo >> $DST1; done; # The move script, this will move all of the results (including the one if you used together script) but not the terms file(terms file is just copied - all into one directory with the given name. You can use relative or absolute path. # example ./move.sh search-nodeleaf - then all of the # this is the only script that needs an input arguments ##!/bin/bash ## USE: ./move.sh <path-to-move-to> ##$ last update: 01-05-2014 #mkdir $1 #mv _allSS_* $1 ## note only copy terms, so terms files stays for next round #cp terms $1 ############################## # UPDATES ON MONITOR SCRIPTS # ############################## # just remove 1 hash mark to make em work #MONITOR SCRIPT: monitor1-tail.sh ##!/bin/bash ## last update: 1/7/2014 #watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;); echo; echo "RESULTS:"; echo "==========="; tail _all*;' ## if you want to do with while loop: ## while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS:"; echo "==========="; tail _all*; sleep 1; done; # #MONITOR SCRIPT: monitor2-lines.sh ##!/bin/bash ## last update 1/7/2014 #watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*;' ## if you wann do with while loop: ## while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*; sleep 1; done; #MONITOR SCRIPT: monitor3-processes.sh ##!/bin/bash ## last update 1/7/2014 #watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;);' ## if you wann do with while loop: ## while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*; sleep 1; done; ##iSCRIPT FOR CPU CONTROL: nicelook-highpriority.sh ############################################### ##!/bin/bash ## update: 1/9/2014 ## usage: ./nicelook-highpriority.sh <path> ## just run look with more priority #nice -n -19 ./look.sh ${1} ##SCRIPT FOR CPU CONTROL: nicelook.sh ############################################### ##!/bin/bash ## update: 1/9/2014 ## usage: ./nicelook.sh <path> ## just run look with nice #nice -n 19 ./look.sh ${1} ##SCRIPT FOR CPU CONTROL: renice-high-priority.sh ############################################### ##!/bin/bash ## update: 1/9/2014 ## make nice of the program more cpu ## prioritize #for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n -19 -p $i; done; ##SCRIPT FOR CPU CONTROL: renice-normal.sh ############################################### ##!/bin/bash ## update: 1/9/2014 ## this put nice back to 0 default so it runs as if was run by ./look and not ./nicelook* #for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n 0 -p $i; done; ##SCRIPT FOR CPU CONTROL: renice.sh ############################################### ##!/bin/bash ## update: 1/9/2014 ## make nice of the program less cpu ## good for huge ops #for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n 19 -p $i; done; *************************************************** *************************************************** SOURCE CODE OF FILE: monitor1-tail.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 monitor1-tail.sh # of bytes: 427 monitor1-tail.sh # of chars: 427 monitor1-tail.sh # of words: 67 monitor1-tail.sh Longer line length: 181 monitor1-tail.sh *************************************************** *************************************************** #!/bin/bash # last update: 1/7/2014 watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;); echo; echo "RESULTS:"; echo "==========="; tail _all*;' # if you want to do with while loop: # while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS:"; echo "==========="; tail _all*; sleep 1; done; *************************************************** *************************************************** SOURCE CODE OF FILE: monitor2-lines.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 monitor2-lines.sh # of bytes: 494 monitor2-lines.sh # of chars: 494 monitor2-lines.sh # of words: 74 monitor2-lines.sh Longer line length: 216 monitor2-lines.sh *************************************************** *************************************************** #!/bin/bash # last update 1/7/2014 watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*;' # if you wann do with while loop: # while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*; sleep 1; done; *************************************************** *************************************************** SOURCE CODE OF FILE: monitor3-processes.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 monitor3-processes.sh # of bytes: 403 monitor3-processes.sh # of chars: 403 monitor3-processes.sh # of words: 63 monitor3-processes.sh Longer line length: 216 monitor3-processes.sh *************************************************** *************************************************** #!/bin/bash # last update 1/7/2014 watch 'top -c -b -n1 | head -n5; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep | egrep -v egrep;);' # if you wann do with while loop: # while true; do clear; "=====`date`======"; echo "PROCESSES:"; echo "==========="; (ps awfuxx | egrep grep;); echo; echo "RESULTS (number of lines):"; echo "=========================="; wc -l _allS*; sleep 1; done; *************************************************** *************************************************** SOURCE CODE OF FILE: move.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 8 move.sh # of bytes: 172 move.sh # of chars: 172 move.sh # of words: 29 move.sh Longer line length: 59 move.sh *************************************************** *************************************************** #!/bin/bash # USE: ./move.sh <path-to-move-to> #$ last update: 01-05-2014 mkdir $1 mv _allSS_* $1 # note only copy terms, so terms files stays for next round cp terms $1 *************************************************** *************************************************** SOURCE CODE OF FILE: together.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 3 together.sh # of bytes: 218 together.sh # of chars: 218 together.sh # of words: 34 together.sh Longer line length: 182 together.sh *************************************************** *************************************************** #!/bin/bash # last update 1/3/2014 DST1="_allTOGETHER_.txt"; for i in `ls | grep _allSS`; do echo "CONCATTING FILE: $i >> $DST1"; echo -e "TERM: $i\n###################" >> $DST1; cat $i >> $DST1; echo >> $DST1; done; *************************************************** *************************************************** SOURCE CODE OF FILE: nicelook-highpriority.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 nicelook-highpriority.sh # of bytes: 136 nicelook-highpriority.sh # of chars: 136 nicelook-highpriority.sh # of words: 20 nicelook-highpriority.sh Longer line length: 42 nicelook-highpriority.sh *************************************************** *************************************************** #!/bin/bash # update: 1/9/2014 # usage: ./nicelook-highpriority.sh <path> # just run look with more priority nice -n -19 ./look.sh ${1} *************************************************** *************************************************** SOURCE CODE OF FILE: nicelook.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 nicelook.sh # of bytes: 113 nicelook.sh # of chars: 113 nicelook.sh # of words: 19 nicelook.sh Longer line length: 29 nicelook.sh *************************************************** *************************************************** #!/bin/bash # update: 1/9/2014 # usage: ./nicelook.sh <path> # just run look with nice nice -n 19 ./look.sh ${1} *************************************************** *************************************************** SOURCE CODE OF FILE: renice-high-priority.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 renice-high-priority.sh # of bytes: 177 renice-high-priority.sh # of chars: 177 renice-high-priority.sh # of words: 37 renice-high-priority.sh Longer line length: 96 renice-high-priority.sh *************************************************** *************************************************** #!/bin/bash # update: 1/9/2014 # make nice of the program more cpu # prioritize for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n -19 -p $i; done; *************************************************** *************************************************** SOURCE CODE OF FILE: renice-normal.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 4 renice-normal.sh # of bytes: 215 renice-normal.sh # of chars: 215 renice-normal.sh # of words: 47 renice-normal.sh Longer line length: 94 renice-normal.sh *************************************************** *************************************************** #!/bin/bash # update: 1/9/2014 # this put nice back to 0 default so it runs as if was run by ./look and not ./nicelook* for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n 0 -p $i; done; *************************************************** *************************************************** SOURCE CODE OF FILE: renice.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 5 renice.sh # of bytes: 183 renice.sh # of chars: 183 renice.sh # of words: 40 renice.sh Longer line length: 95 renice.sh *************************************************** *************************************************** #!/bin/bash # update: 1/9/2014 # make nice of the program less cpu # good for huge ops for i in `ps ax | egrep grep | egrep -v egrep | awk '{print $1}'`; do renice -n 19 -p $i; done; *************************************************** *************************************************** SOURCE CODE OF FILE: smartlook.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 192 smartlook.sh # of bytes: 7260 smartlook.sh # of chars: 7260 smartlook.sh # of words: 990 smartlook.sh Longer line length: 112 smartlook.sh *************************************************** *************************************************** #!/bin/bash # ./smartlook.sh <number of terms per jobs> # variations: just change the "look" variable # ./smartlook-nice.sh <number of terms per jobs> # ./smartlook-priority.sh <number of terms per jobs> # look="look.sh" # look="nicelook.sh" # look="nicelook-highpriority.sh" # if no specified then set to 10 # AS JOB MIGHT BE LONG LETS CLEAN UP BY CATCHING CONTROL-C WITH TRAP trap ctrl_c INT function ctrl_c() { echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEAN UP TRIGGERED DUE TO:" echo "CONTROL-C" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEANING UP - putting terms file as it was - and killing all greps" echo "RECOMMENDED: delete _allSS files that were cancelled - didnt delete just incase you needed them" echo "RECOMMENDED CONTINUED: ./cleanup.sh does just that" killall -9 grep mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time2}" exit 2 } # PRINT USAGE usage123 () { ME123=`basename $0` echo "termsearch - by kostia - 2014" echo "Usage: $ME123 <number of terms per jobs> <folder or file to look thru>" echo "Usage: $ME123 <folder or file to look thru>" echo "When no <number of terms per jobs> specified it will default to 0" exit 1 } # CHECK PROGRESS SCRIPT check_process() { #echo -n "" [ "$1" = "" ] && return 0 # if process name is nothing then fail, this will be grep so it will never fail [ `pgrep -n $1` ] && return 1 || return 0 # if process exists then 1 if doesnt then 0 } # MAIN SCRIPT # CHECK IF NO ARGS if [ $# -eq 0 ] # 0 args then usage123 fi if [ $# -gt 2 ] # more then 2 arg then usage123 fi if [ -z "$1" ] # no argument in first arg then usage123 fi if [ $# -eq 1 ] # if 1 argument it should be folder or file Usage: $ME123 <folder or file to look thru> then if [ -d "$1" ] ; then # if directory echo "Will look thru DIRECTORY: $1" else if [ -f "$1" ] ; then echo "Will look thru FILE: $1" else usage123 fi fi n=10; FOLDER=$1 echo "Defauling to 10 terms per job" echo "Setting n=10" fi if [ $# -eq 2 ] # if 2 Usage: $ME123 <number of terms per jobs> <folder or file to look thru> then n=$1 FOLDER=$2 if [ -d "$2" ] ; then # if directory echo "Will look thru DIRECTORY: $2" else if [ -f "$2" ] ; then echo "Will look thru FILE: $2" else usage123 fi fi fi # SETTING IMPORTANT VARIABLES look="look.sh" # look="nicelook.sh" # look="nicelook-highpriority.sh" searchgrep="grep" time0=`date +ymd%Y-%m-%d-t%T | tr : -` echo "Folder/File that we are term searching thru: ${FOLDER}" echo "##############################################################################################" echo "############################### START: $time0 ###############################" echo "##############################################################################################" tfile="terms" # COPY TERMS FILE TO TERMS-CURRENT (WE WILL WORK OFF TERMS CURRENT) tmainfile="${tfile}-main-${time0}" echo "Main File Was Copied To: ${tmainfile}" cp -vf ${tfile} ${tmainfile} # MAKE NTFILE - TEMPORARY - TO SHOW WHAT TERM # BEING COPIED (SIMPLE HACK) ntfile="${tmainfile}-numbered" cat ${tmainfile} | nl > ${ntfile} # N total number of lines # n is the number of terms per job, given as 1st parameter N=`wc -l ${tmainfile} | awk '{print $1;}'` #n=$1 total=$((N/n)) echo "Number of terms: ${N}, Terms Per Job: ${n}, Number Of Jobs: ${total}" for i in `seq 1 $((total+1))`; do echo "-------------------------------------------------------------------------------------------------------" echo "------------------------------ STARTING ${i}/${total} --------------------------------------" echo "-------------------------------------------------------------------------------------------------------" date; #echo "* n=$n N=$N i=$i total=$total" START=$((i*n-n+1)) END=$((START+n-1)) if [ ${i} -eq ${total} ]; then END=${N} fi len=$((END-START+1)) echo "* n=$n, N=$N, i=$i, total=$total, START=$START, END=$END, len=$len" ###### echo "* Job number ${i}: iterating thru ${START} -> ${END}" # USE NTFILE TO TELL US WHAT TERMS and THEIR NUMBER ARE BEING WORKED ON echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" cat ${ntfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" | nl echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" time1=`date +ymd%Y-%m-%d-t%T | tr : -` curterms="${tfile}-work-${START}-to-${END}-${time1}" # EXTRACT TERMS TO WORK ON FOR THIS JOB TO CURRENT-TERMS FILE ##### echo "Current Terms File: ${curterms}" cat ${tmainfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" > ${curterms} ###### echo "- NOTE: Overwriting ${curterms} over ${tfile} and will work on it" ###### echo "- NOTE: Don't worry original ${tfile} is still at ${tmainfile}" cp -vf ${curterms} ${tfile} ##### echo "Looking thru this:" # echo "~~~~~~~~~~~ numbered current terms ~~~~~~~~~" # cat ${tfile} | nl # echo "~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~" ##### echo "Launching ${look} on ${n} terms" # LAUNCHING MAIN LOOK THAT RUNS IN BACKGROUND - NOTE LOOK OPERATES ON terms FILE # # # killing all other greps ##### echo "killing all greps before looking" killall -9 grep echo "Launching: ./${look} ${FOLDER}" ./${look} ${FOLDER} # sleep 1 # # echo "*************************************************************" echo "**** WAITING FOR COMPLETION ${i} - CHECKING EVERY 5 sec *****" echo "*************************************************************" # MONITORING UNTIL LOOK IS DONE while [ 1 ]; do ##### ts="`date +ymd%Y-%m-%d-t%T` " ts="X" echo -n "${ts}" check_process ${searchgrep} # WHEN LOOK IS DONE LET US KNOW AND BREAK LOOP [ $? -eq 0 ] && echo -e "\n*** Job ${i} - Complete - GREPS Finished ***" && break sleep 5 done ##### echo "**** FINISHED ${i} - MOVING TO NEXT JOB *****" # FOR CLEAN UP OF CURTERMS UNHASH THIS: # rm -f ${curterms} time1a=`date +ymd%Y-%m-%d-t%T | tr : -` echo "STARTED THIS SUB-JOB OF $n TERMS ON: ${time1}" echo "ENDED THIS SUB-JOB OF $n TERMS ON: ${time1a}" echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------ ENDING ${i}/${total} --------------------------------------" echo "-----------------------------------------------------------------------------------------------------" done # WHEN DONE PUT TERMS FILE BACK AS THEY WERE echo "CLEANING UP - putting terms file as it was" mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time2}" echo "############################################################################################" echo "############################### END: $time2 ###############################" echo "############################################################################################" *************************************************** *************************************************** SOURCE CODE OF FILE: smartlook-nice.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 192 smartlook-nice.sh # of bytes: 7260 smartlook-nice.sh # of chars: 7260 smartlook-nice.sh # of words: 990 smartlook-nice.sh Longer line length: 112 smartlook-nice.sh *************************************************** *************************************************** #!/bin/bash # ./smartlook.sh <number of terms per jobs> # variations: just change the "look" variable # ./smartlook-nice.sh <number of terms per jobs> # ./smartlook-priority.sh <number of terms per jobs> # look="look.sh" # look="nicelook.sh" # look="nicelook-highpriority.sh" # if no specified then set to 10 # AS JOB MIGHT BE LONG LETS CLEAN UP BY CATCHING CONTROL-C WITH TRAP trap ctrl_c INT function ctrl_c() { echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEAN UP TRIGGERED DUE TO:" echo "CONTROL-C" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEANING UP - putting terms file as it was - and killing all greps" echo "RECOMMENDED: delete _allSS files that were cancelled - didnt delete just incase you needed them" echo "RECOMMENDED CONTINUED: ./cleanup.sh does just that" killall -9 grep mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time2}" exit 2 } # PRINT USAGE usage123 () { ME123=`basename $0` echo "termsearch - by kostia - 2014" echo "Usage: $ME123 <number of terms per jobs> <folder or file to look thru>" echo "Usage: $ME123 <folder or file to look thru>" echo "When no <number of terms per jobs> specified it will default to 0" exit 1 } # CHECK PROGRESS SCRIPT check_process() { #echo -n "" [ "$1" = "" ] && return 0 # if process name is nothing then fail, this will be grep so it will never fail [ `pgrep -n $1` ] && return 1 || return 0 # if process exists then 1 if doesnt then 0 } # MAIN SCRIPT # CHECK IF NO ARGS if [ $# -eq 0 ] # 0 args then usage123 fi if [ $# -gt 2 ] # more then 2 arg then usage123 fi if [ -z "$1" ] # no argument in first arg then usage123 fi if [ $# -eq 1 ] # if 1 argument it should be folder or file Usage: $ME123 <folder or file to look thru> then if [ -d "$1" ] ; then # if directory echo "Will look thru DIRECTORY: $1" else if [ -f "$1" ] ; then echo "Will look thru FILE: $1" else usage123 fi fi n=10; FOLDER=$1 echo "Defauling to 10 terms per job" echo "Setting n=10" fi if [ $# -eq 2 ] # if 2 Usage: $ME123 <number of terms per jobs> <folder or file to look thru> then n=$1 FOLDER=$2 if [ -d "$2" ] ; then # if directory echo "Will look thru DIRECTORY: $2" else if [ -f "$2" ] ; then echo "Will look thru FILE: $2" else usage123 fi fi fi # SETTING IMPORTANT VARIABLES # look="look.sh" look="nicelook.sh" # look="nicelook-highpriority.sh" searchgrep="grep" time0=`date +ymd%Y-%m-%d-t%T | tr : -` echo "Folder/File that we are term searching thru: ${FOLDER}" echo "##############################################################################################" echo "############################### START: $time0 ###############################" echo "##############################################################################################" tfile="terms" # COPY TERMS FILE TO TERMS-CURRENT (WE WILL WORK OFF TERMS CURRENT) tmainfile="${tfile}-main-${time0}" echo "Main File Was Copied To: ${tmainfile}" cp -vf ${tfile} ${tmainfile} # MAKE NTFILE - TEMPORARY - TO SHOW WHAT TERM # BEING COPIED (SIMPLE HACK) ntfile="${tmainfile}-numbered" cat ${tmainfile} | nl > ${ntfile} # N total number of lines # n is the number of terms per job, given as 1st parameter N=`wc -l ${tmainfile} | awk '{print $1;}'` #n=$1 total=$((N/n)) echo "Number of terms: ${N}, Terms Per Job: ${n}, Number Of Jobs: ${total}" for i in `seq 1 $((total+1))`; do echo "-------------------------------------------------------------------------------------------------------" echo "------------------------------ STARTING ${i}/${total} --------------------------------------" echo "-------------------------------------------------------------------------------------------------------" date; #echo "* n=$n N=$N i=$i total=$total" START=$((i*n-n+1)) END=$((START+n-1)) if [ ${i} -eq ${total} ]; then END=${N} fi len=$((END-START+1)) echo "* n=$n, N=$N, i=$i, total=$total, START=$START, END=$END, len=$len" ###### echo "* Job number ${i}: iterating thru ${START} -> ${END}" # USE NTFILE TO TELL US WHAT TERMS and THEIR NUMBER ARE BEING WORKED ON echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" cat ${ntfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" | nl echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" time1=`date +ymd%Y-%m-%d-t%T | tr : -` curterms="${tfile}-work-${START}-to-${END}-${time1}" # EXTRACT TERMS TO WORK ON FOR THIS JOB TO CURRENT-TERMS FILE ##### echo "Current Terms File: ${curterms}" cat ${tmainfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" > ${curterms} ###### echo "- NOTE: Overwriting ${curterms} over ${tfile} and will work on it" ###### echo "- NOTE: Don't worry original ${tfile} is still at ${tmainfile}" cp -vf ${curterms} ${tfile} ##### echo "Looking thru this:" # echo "~~~~~~~~~~~ numbered current terms ~~~~~~~~~" # cat ${tfile} | nl # echo "~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~" ##### echo "Launching ${look} on ${n} terms" # LAUNCHING MAIN LOOK THAT RUNS IN BACKGROUND - NOTE LOOK OPERATES ON terms FILE # # # killing all other greps ##### echo "killing all greps before looking" killall -9 grep echo "Launching: ./${look} ${FOLDER}" ./${look} ${FOLDER} # sleep 1 # # echo "*************************************************************" echo "**** WAITING FOR COMPLETION ${i} - CHECKING EVERY 5 sec *****" echo "*************************************************************" # MONITORING UNTIL LOOK IS DONE while [ 1 ]; do ##### ts="`date +ymd%Y-%m-%d-t%T` " ts="X" echo -n "${ts}" check_process ${searchgrep} # WHEN LOOK IS DONE LET US KNOW AND BREAK LOOP [ $? -eq 0 ] && echo -e "\n*** Job ${i} - Complete - GREPS Finished ***" && break sleep 5 done ##### echo "**** FINISHED ${i} - MOVING TO NEXT JOB *****" # FOR CLEAN UP OF CURTERMS UNHASH THIS: # rm -f ${curterms} time1a=`date +ymd%Y-%m-%d-t%T | tr : -` echo "STARTED THIS SUB-JOB OF $n TERMS ON: ${time1}" echo "ENDED THIS SUB-JOB OF $n TERMS ON: ${time1a}" echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------ ENDING ${i}/${total} --------------------------------------" echo "-----------------------------------------------------------------------------------------------------" done # WHEN DONE PUT TERMS FILE BACK AS THEY WERE echo "CLEANING UP - putting terms file as it was" mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time2}" echo "############################################################################################" echo "############################### END: $time2 ###############################" echo "############################################################################################" *************************************************** *************************************************** SOURCE CODE OF FILE: smartlook-priority.sh --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 192 smartlook-priority.sh # of bytes: 7260 smartlook-priority.sh # of chars: 7260 smartlook-priority.sh # of words: 990 smartlook-priority.sh Longer line length: 112 smartlook-priority.sh *************************************************** *************************************************** #!/bin/bash # ./smartlook.sh <number of terms per jobs> # variations: just change the "look" variable # ./smartlook-nice.sh <number of terms per jobs> # ./smartlook-priority.sh <number of terms per jobs> # look="look.sh" # look="nicelook.sh" # look="nicelook-highpriority.sh" # if no specified then set to 10 # AS JOB MIGHT BE LONG LETS CLEAN UP BY CATCHING CONTROL-C WITH TRAP trap ctrl_c INT function ctrl_c() { echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEAN UP TRIGGERED DUE TO:" echo "CONTROL-C" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "CLEANING UP - putting terms file as it was - and killing all greps" echo "RECOMMENDED: delete _allSS files that were cancelled - didnt delete just incase you needed them" echo "RECOMMENDED CONTINUED: ./cleanup.sh does just that" killall -9 grep mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL - CANCELED - OPERATION OF $N TOTAL TERM[S]: ${time2}" exit 2 } # PRINT USAGE usage123 () { ME123=`basename $0` echo "termsearch - by kostia - 2014" echo "Usage: $ME123 <number of terms per jobs> <folder or file to look thru>" echo "Usage: $ME123 <folder or file to look thru>" echo "When no <number of terms per jobs> specified it will default to 0" exit 1 } # CHECK PROGRESS SCRIPT check_process() { #echo -n "" [ "$1" = "" ] && return 0 # if process name is nothing then fail, this will be grep so it will never fail [ `pgrep -n $1` ] && return 1 || return 0 # if process exists then 1 if doesnt then 0 } # MAIN SCRIPT # CHECK IF NO ARGS if [ $# -eq 0 ] # 0 args then usage123 fi if [ $# -gt 2 ] # more then 2 arg then usage123 fi if [ -z "$1" ] # no argument in first arg then usage123 fi if [ $# -eq 1 ] # if 1 argument it should be folder or file Usage: $ME123 <folder or file to look thru> then if [ -d "$1" ] ; then # if directory echo "Will look thru DIRECTORY: $1" else if [ -f "$1" ] ; then echo "Will look thru FILE: $1" else usage123 fi fi n=10; FOLDER=$1 echo "Defauling to 10 terms per job" echo "Setting n=10" fi if [ $# -eq 2 ] # if 2 Usage: $ME123 <number of terms per jobs> <folder or file to look thru> then n=$1 FOLDER=$2 if [ -d "$2" ] ; then # if directory echo "Will look thru DIRECTORY: $2" else if [ -f "$2" ] ; then echo "Will look thru FILE: $2" else usage123 fi fi fi # SETTING IMPORTANT VARIABLES # look="look.sh" # look="nicelook.sh" look="nicelook-highpriority.sh" searchgrep="grep" time0=`date +ymd%Y-%m-%d-t%T | tr : -` echo "Folder/File that we are term searching thru: ${FOLDER}" echo "##############################################################################################" echo "############################### START: $time0 ###############################" echo "##############################################################################################" tfile="terms" # COPY TERMS FILE TO TERMS-CURRENT (WE WILL WORK OFF TERMS CURRENT) tmainfile="${tfile}-main-${time0}" echo "Main File Was Copied To: ${tmainfile}" cp -vf ${tfile} ${tmainfile} # MAKE NTFILE - TEMPORARY - TO SHOW WHAT TERM # BEING COPIED (SIMPLE HACK) ntfile="${tmainfile}-numbered" cat ${tmainfile} | nl > ${ntfile} # N total number of lines # n is the number of terms per job, given as 1st parameter N=`wc -l ${tmainfile} | awk '{print $1;}'` #n=$1 total=$((N/n)) echo "Number of terms: ${N}, Terms Per Job: ${n}, Number Of Jobs: ${total}" for i in `seq 1 $((total+1))`; do echo "-------------------------------------------------------------------------------------------------------" echo "------------------------------ STARTING ${i}/${total} --------------------------------------" echo "-------------------------------------------------------------------------------------------------------" date; #echo "* n=$n N=$N i=$i total=$total" START=$((i*n-n+1)) END=$((START+n-1)) if [ ${i} -eq ${total} ]; then END=${N} fi len=$((END-START+1)) echo "* n=$n, N=$N, i=$i, total=$total, START=$START, END=$END, len=$len" ###### echo "* Job number ${i}: iterating thru ${START} -> ${END}" # USE NTFILE TO TELL US WHAT TERMS and THEIR NUMBER ARE BEING WORKED ON echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" cat ${ntfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" | nl echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" time1=`date +ymd%Y-%m-%d-t%T | tr : -` curterms="${tfile}-work-${START}-to-${END}-${time1}" # EXTRACT TERMS TO WORK ON FOR THIS JOB TO CURRENT-TERMS FILE ##### echo "Current Terms File: ${curterms}" cat ${tmainfile} | awk "{S=$START;E=$END;if(NR>=S && NR<=E){print \$0;}}" > ${curterms} ###### echo "- NOTE: Overwriting ${curterms} over ${tfile} and will work on it" ###### echo "- NOTE: Don't worry original ${tfile} is still at ${tmainfile}" cp -vf ${curterms} ${tfile} ##### echo "Looking thru this:" # echo "~~~~~~~~~~~ numbered current terms ~~~~~~~~~" # cat ${tfile} | nl # echo "~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~" ##### echo "Launching ${look} on ${n} terms" # LAUNCHING MAIN LOOK THAT RUNS IN BACKGROUND - NOTE LOOK OPERATES ON terms FILE # # # killing all other greps ##### echo "killing all greps before looking" killall -9 grep echo "Launching: ./${look} ${FOLDER}" ./${look} ${FOLDER} # sleep 1 # # echo "*************************************************************" echo "**** WAITING FOR COMPLETION ${i} - CHECKING EVERY 5 sec *****" echo "*************************************************************" # MONITORING UNTIL LOOK IS DONE while [ 1 ]; do ##### ts="`date +ymd%Y-%m-%d-t%T` " ts="X" echo -n "${ts}" check_process ${searchgrep} # WHEN LOOK IS DONE LET US KNOW AND BREAK LOOP [ $? -eq 0 ] && echo -e "\n*** Job ${i} - Complete - GREPS Finished ***" && break sleep 5 done ##### echo "**** FINISHED ${i} - MOVING TO NEXT JOB *****" # FOR CLEAN UP OF CURTERMS UNHASH THIS: # rm -f ${curterms} time1a=`date +ymd%Y-%m-%d-t%T | tr : -` echo "STARTED THIS SUB-JOB OF $n TERMS ON: ${time1}" echo "ENDED THIS SUB-JOB OF $n TERMS ON: ${time1a}" echo "-----------------------------------------------------------------------------------------------------" echo "------------------------------ ENDING ${i}/${total} --------------------------------------" echo "-----------------------------------------------------------------------------------------------------" done # WHEN DONE PUT TERMS FILE BACK AS THEY WERE echo "CLEANING UP - putting terms file as it was" mv -vf ${tmainfile} ${tfile} rm -vf ${ntfile} rm -vf "${tfile}-work-"* time2=`date +ymd%Y-%m-%d-t%T | tr : -` echo "START TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time0}" echo "END TIME OF FULL OPERATION OF $N TOTAL TERM[S]: ${time2}" echo "############################################################################################" echo "############################### END: $time2 ###############################" echo "############################################################################################" *************************************************** *************************************************** SOURCE CODE OF FILE: terms --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 3 terms # of bytes: 18 terms # of chars: 18 terms # of words: 3 terms Longer line length: 5 terms *************************************************** *************************************************** term1 term2 term3 *************************************************** *************************************************** SOURCE CODE OF FILE: backup.script --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 20 backup.script # of bytes: 1056 backup.script # of chars: 1056 backup.script # of words: 122 backup.script Longer line length: 115 backup.script *************************************************** *************************************************** #!/bin/bash SCRIPTS="cleanup.sh look.sh monitor1-tail.sh monitor2-lines.sh monitor3-processes.sh move.sh together.sh" SCRIPTS="$SCRIPTS nicelook-highpriority.sh nicelook.sh renice-high-priority.sh renice-normal.sh renice.sh" SCRIPTS="$SCRIPTS smartlook.sh smartlook-nice.sh smartlook-priority.sh" echo "* REMOVING OLD TGZ FILE" rm -f termsearch.tgz echo "* RENAMING TERMS TO .tempterms123" mv terms .tempterms123 echo "* MAKING SHOWCASE terms FILE WITH TERMS: term1 THRU term3" echo -e "term1\nterm2\nterm3" > terms echo "* GRABBING SOURCE CODE" ./print.script > termsearch-all-code.txt echo "* TAR GZIPPING EVERY SCRIPT AND terms FILE INTO termsearch.tgz" tar -zcvf termsearch.tgz termsearch-all-code.txt ${SCRIPTS} terms backup.script print.script echo "* COPYING termsearch.tgz AND ALL SOURCE CODE termsearch-all-code.txt TO WEB SERVER /var/www" cp termsearch.tgz termsearch-all-code.txt /var/www/ echo "* RENAME TEMP TERMS BACK TO ORIGINAL terms FILE - REMOVING SHOWCASE terms FILE AND RESTORING YOUR terms FILE" mv .tempterms123 terms echo "* DONE!" *************************************************** *************************************************** SOURCE CODE OF FILE: print.script --------------------------------------------------- Date of code: Wed Jan 22 18:57:12 PST 2014 # of lines: 36 print.script # of bytes: 1199 print.script # of chars: 1199 print.script # of words: 128 print.script Longer line length: 130 print.script *************************************************** *************************************************** #!/bin/bash # update 1/9/2014 SCRIPTS="cleanup.sh look.sh monitor1-tail.sh monitor2-lines.sh monitor3-processes.sh move.sh together.sh" #cant include extract.sh SCRIPTS="$SCRIPTS nicelook-highpriority.sh nicelook.sh renice-high-priority.sh renice-normal.sh renice.sh" SCRIPTS="$SCRIPTS smartlook.sh smartlook-nice.sh smartlook-priority.sh" echo "TERMSEARCH SOURCE CODE" echo "#######################" echo "#######################" echo echo "SOURCE CODE PRINTED USING `basename $0` ON `date`" echo "Printing Code From the following files:" echo *sh terms backup.script print.script echo echo echo for i in ${SCRIPTS} terms backup.script print.script do echo "***************************************************" echo "***************************************************" echo "SOURCE CODE OF FILE: $i" echo "---------------------------------------------------" echo "Date of code: `date`" echo "# of lines: `wc -l $i`" echo "# of bytes: `wc -c $i`" echo "# of chars: `wc -m $i`" echo "# of words: `wc -w $i`" echo "Longer line length: `wc -L $i`" echo "***************************************************" echo "***************************************************" echo cat $i echo echo echo done |