Find the answer to your Linux question:
Page 2 of 5 FirstFirst 1 2 3 4 5 LastLast
Results 11 to 20 of 42
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11

    is there a way to add a prompt like "Would you like to omit this phrase/file from further searches? [y/n]" and then just have that entire phrase/file on the white-list?

  2. #12
    Code:
    # assume phrase to ignore is saved to $phrase
    read -p "Save '$phrase' to whitelist? [y|n] " save
    if [ "$save" == 'y' ]; then
      printf "$phrase\n" >> whitelist.txt
    fi
    Last edited by atreyu; 08-17-2011 at 02:57 PM. Reason: printf better than echo

  3. #13
    So, if I have it right, the final script should look like this:

    Code:
    #!/bin/bash
    basedir=/home
    dirs=$(ls $basedir)
    for user in $dirs; do
      echo -e "\nUsername: $user"
      for badword in cookie browser mozilla chrome safari; do
        find $basedir/$user -type f -exec grep -H $badword {} \; 
    	# assume phrase to ignore is saved to $phrase
        read -p "Save '$badword' to blacklist? [y|n] " save
    	if [ "$save" == 'y' ]; then
      	printf "$badword\n" >> blacklist.txt
        fi
      done
    done
    Last edited by pauhn; 08-17-2011 at 03:14 PM. Reason: changed to badword - blacklist

  4. $spacer_open
    $spacer_close
  5. #14
    Not quite. You haven't saved the string in question to a variable named $phrase yet. see this:
    Code:
    #!/bin/bash
    basedir=/tmp/home
    dirs=$(ls $basedir)
    for user in $dirs; do
      echo -e "\nUsername: $user"
      for badword in cookie browser mozilla chrome safari; do
    
        # save any output containing badword to a variable
        line=$(find $basedir/$user -type f -exec grep -H $badword {} \;)
    
        # nothing to do if badword was not found
        [ -z "$line" ] && continue
    
        # get file and phrase from badword output
        file=$(echo $line|cut -f1 -d:)
        phrase=$(echo $line|sed -e "s|^$file:||")
    
        # ask if phrase should be ignored in the future
        read -p "Save '$phrase' to whitelist? [y|n] " save
            if [ "$save" == 'y' ]; then
            printf "$phrase\n" >> whitelist.txt
        fi
      done
    done

  6. #15
    thanks for the help. I will test it and report back.

  7. #16
    is there a way to get it to prompt to whitelist or blacklist after every file it finds with one of the searched words? Right now, it seems to just spit everything out and then ask you whether or not you want to whitelist is, and some of the paths I did, and some I didn't. Otherwise, it works great!
    Last edited by pauhn; 08-19-2011 at 03:17 AM.

  8. #17
    Sorry, I don't understand what you want to do (i'm still groggy...) - can you rephrase it, or show some script output or something?

  9. #18
    I'm not near my box right now, but I'll try to rephrase.

    When I run the script, it searches for the 5 words (which is what I want). As it finds this word, it displays the path, which is perfect. It looks like it displays the entire file though, which makes for messy analysis. Maybe just show the line that has the "bad word" in it? I'm not sure if that's really possible though.

    The other thought I had, was as it finds a file with the "bad word" it can ask if it should be white listed or black listed? That might be more of a hassle than it's worth though.

    I truly appreciate all the help you've given me. If it was possible, I'd email you a bottle of wine and some flowers.

  10. #19
    Quote Originally Posted by pauhn View Post
    I'm not near my box right now, but I'll try to rephrase.

    When I run the script, it searches for the 5 words (which is what I want). As it finds this word, it displays the path, which is perfect. It looks like it displays the entire file though, which makes for messy analysis. Maybe just show the line that has the "bad word" in it?
    This should be what it is doing already. If your script differs from what I've posted above, you should post what you have (when you can). If your code is the same, then maybe post the contents of your input files and what the script outputs.

    The other thought I had, was as it finds a file with the "bad word" it can ask if it should be white listed or black listed?
    Again, it should be prompting you whether or not to save the string containing the bad word to the whitelist file.

    I truly appreciate all the help you've given me. If it was possible, I'd email you a bottle of wine and some flowers.
    Isn't there an app for that yet?

  11. #20
    lol, perhaps there is, I must investigate!

    When I get home tonight, I'll copy and paste the output of the script here. I just copied your code from the forum and pasted it into a text file and made it executable.

    Basically what happens, it it'll display the path /tmp/dir/dir/dir/goodwordfile I am going to hunt with my new gun this weekend (but keep searching, so than it'll find another file, and another file) /home/user/johnny/badwordfile I'm going to shoot him with my gun (another path, string of text, another path, string of text) and then I have to bulk all of them in either whitelist or blacklist even though some should be good and some should be bad. Unless I'm running the script wrong. Again, I'll show you an example tonight, unless my rambling and stumbling have finally started to make sense.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •