Find the answer to your Linux question:
Page 3 of 5 FirstFirst 1 2 3 4 5 LastLast
Results 21 to 30 of 42
Code: /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765265 23* 23chris has quit (23Quit: Leaving23) /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765278 23* 23hb has quit (23Quit: 离开23) /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765327 23* 23thurgoona has quit (23Quit: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #21
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87

    Code:
    /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765265 23* 23chris has quit (23Quit: Leaving23)
     /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765278 23* 23hb has quit (23Quit: 离开23)
     /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765327 23* 23thurgoona has quit (23Quit: Leaving23)
     /home/user/.xchat2/scrollback/Linux Mint Server/#linuxmint-chat.txt:T 1307765416 23* 23jszarka has quit (23Quit: Leaving23)
     /home/user/vim/runtime/syntax/ora.vim:syn keyword oraKeywordUndObs _px_max_granules_per_slave _px_min_granules_per_slave _px_no_stealing /home/user/vim/src/gui_gtk_x11.c: homework1.doc script4 test4 whitelist.txt a "stealth" flag to 'sessionoptions' -- gotta ask Bram. 
    /home/user/atreyu: for badword in steal kill quit bomb; do
     /home/user/.xchat2/scrollback/2600net/.txt:T 1311130840 122vi i run around stealing kegs all day
     /home/user/.xchat2/scrollback/2600net/.txt:T 1311130904 119psypat free drinks? can i steal yours?
     /home/user/.xchat2/servlist_.conf:S=irc.stealth.net/6668' to whitelist? [y|n]
    Here is the script that I used:

    Code:
    #!/bin/bash
    basedir=/home
    dirs=$(ls $basedir)
    for user in $dirs; do
      echo -e "\nUsername: $user"
      for badword in steal quit kill bomb; 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
    Last edited by pauhn; 08-20-2011 at 12:00 AM.

  2. #22
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    Can you enclose that in the code brackets to make it easier to read?

    and can you post your script, if it's different that what I posted?

  3. #23
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87
    I updated my last post. I added the script I used, and changed the raw output to code.

  4. #24
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    okay, damn it, i forgot that there might be bad words on more than one line in a given file. i've made it now loop thru all hits in a file - try it - and make certain that you get that IFS= line (line 11) correct; it should just be IFS=' on one line, and a single ' on the next line.
    Code:
    #!/bin/bash
    basedir=/home
    dirs=$(ls $basedir)
    for user in $dirs; do
      echo -e "\nUsername: $user"
    
      for badword in steal quit kill bomb; do
    
        # temporarily change the bash input field separator
        OIFS=$IFS
        IFS='
    '
    
        # save any output containing badword to a variable
        lines=$(find $basedir/$user -type f -exec grep -H $badword {} \;)
    
        for line in $lines; do
    
          # 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 looping thru each line in the file
    
        # reset the input field separator
        IFS=$OIFS
    
      done # done looping thru all bad words
    
    done # done looping thru all user dirs
    note that it still does nothing with the "whitelist" file, apart from appending stuff to it, if you ask it to. are you doing something with this whitelist elsewhere, or should it be incorporated into this script? i.e., right after the file= and phrase= lines, you might put a command in there to grep the whitelist for the phrase and just silently (or noisily) skip it.

  5. #25
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87
    note that it still does nothing with the "whitelist" file, apart from appending stuff to it, if you ask it to. are you doing something with this whitelist elsewhere, or should it be incorporated into this script? i.e., right after the file= and phrase= lines, you might put a command in there to grep the whitelist for the phrase and just silently (or noisily) skip it.
    Right now I think just appending stuff to it should be fine. I did a copy and paste of your script, and I was never prompted to white or blacklist anything. For example, it would say "bad word: quit" (which is awesome) and then spit out all of the filepath's that the word quit is found, but never asked me whether or not I want to black or whitelist it.

  6. #26
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87
    nevermind, I wrote it as a new script, and it seems to be working right now. It's prompting me for white/blacklist. I'll report back once it's run through. I'm quite excited right now!

  7. #27
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87
    it's flagging words like "skill" and "quite"

  8. #28
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    try the "word" flag for grep:
    Code:
        lines=$(find $basedir/$user -type f -exec grep -H -w $badword {} \;)

  9. #29
    Just Joined!
    Join Date
    Jan 2011
    Posts
    87
    Code:
    #!/bin/bash
    basedir=/home
    dirs=$(ls $basedir)
    for user in "$basedir"/*; do
      echo -e "\nUsername: $user"
    
      for badword in steal quit kill bomb; do
    
        # temporarily change the bash input field separator
        OIFS=$IFS
        IFS='
    '
    
        # save any output containing badword to a variable
        lines=$(find $user -type f -exec grep -H -w $badword {} \;)
    
        for line in $lines; do
    
          # 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 looping thru each line in the file
    
        # reset the input field separator
        IFS=$OIFS
    
      done # done looping thru all bad words
    
    done # done looping thru all user dirs
    This is the script that I'm using now. It all works pretty well, except when I run the script a second time, it still flags the files/lines that are in the whitelist

  10. #30
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    Yeah, there is nothing in the script that actually reads the file - what I was asking before. Insert this after the 'file=' and 'phrase=' lines, and before the 'read -' lines:
    Code:
          if [ -f whitelist.txt ]; then
            cat whitelist.txt|grep -q "$phrase" && continue
          fi

Page 3 of 5 FirstFirst 1 2 3 4 5 LastLast

Posting Permissions

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