Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> bash script help, need help making a script
sparda963
post Feb 27 2006, 08:05 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 27-February 06
Member No.: 6,107



I am fairly new to my job and trying to learn linux as I go. I have a job at a high school and the admin is in charge of maintaing the acceptable use policy and reporting any violations to the principal. One of the things he needs to do is look at users files to make sure they arnt writing letters with threatening subjects such as plans to kill a teacher or place a bomb somewhere in the building.

I know there has to be an easier way to do this then reading through each persons files every once in a while, but I really have no idea where to start. From my somewhat limited knowledge of linux so far I know I must use the grep command for the bad words on the all the users files. I also need to loop this untill it has scanned all the files and then redirect the output to a file.

To make the report easy to read I would need it to say something like "User `username` has the word `badword` in the file `directory path to file`". That would have to happen for each file that has one of the words in the file.

I know there has to be a way to do this, any help would be greatly appreciated.
Go to the top of the page
 
+Quote Post
DS2K3
post Feb 28 2006, 11:35 AM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,284
Joined: 14-November 04
From: Southampton, Hampshire
Member No.: 4,165



There are a couple of problems with that method - Firstly, scanning files that aren't plain-text is a bit hit and miss, since they often dont contain portions of text which can be read without using the correct filter, so would need to be converted to a plain-text version first, which would be quite processor intensive. Secondly, in order to maximise the efficieny of the scanner you would need to keep a list of files which have been scanned, and when they were scanned, so that you only need to scan files that have changed since that time - That would require soe kind of database. So, you would probably be better of using a proper application to do it for you. (Perhaps a modified virus scanner?)

I'm not particularly hot on shell scripting, so I'm not really sure how you would go about implementing it in a shell script.

If you want to filter email, then there are numerous mail-scanning packages available for servers like postfix.

D


--------------------
Fixed your problem? Let us know!
richard@linuxhelp.net

www.Gathr.co.uk Online Event Management
Go to the top of the page
 
+Quote Post
sparda963
post Feb 28 2006, 05:01 PM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 27-February 06
Member No.: 6,107



Ok after doing some work on this yesterday I have come up with the following code, but it has one problem. I will post the code first, then post the problem im having after the code.

CODE
for BADWORD in kill bomb steal
do
GLOBAL=`grep -r -F -i "$BADWORD" /home`
UNAME=`echo $GLOBAL | cut -d "/" -f 3`
WORD=`echo $BADWORD`
LOC=`echo $GLOBAL | cut -d ":" -f 1`
echo "User $UNAME has the word $WORD in $LOC"
done


Now this almost works perfectly, except that there is one problem. When more then one file is found with one of the words, we will say kill for example, the output to the GLOBAL variable puts all the information for each of the files found into one line with a ":" delimiter. What I need to have happen is that each of the delimited lines needs to be a seperate line in the output. Here is an example.

Current output of GLOBAL variable
/home/testa/bad:I am going to kill you /home/testb/bad:I am going to kill you /home/testc/bad:I am going to kill you
/home/testa/bad:I am making a bomb /home/testb/bad:I am making a bomb /home/testc/bad:I am making a bomb

What I need the output to the GLOBAL variable to be
/home/testa/bad:I am going to kill you
/home/testb/bad:I am going to kill you
/home/testc/bad:I am going to kill you
/home/testa/bad:I am making a bomb
/home/testb/bad:I am making a bomb
/home/testc/bad:I am making a bomb

Is there anyway i can controll the grep command to get this to happen?
Go to the top of the page
 
+Quote Post
Hemant
post Mar 7 2006, 04:39 PM
Post #4


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



I would rather advise you to use another loop:
CODE
#!/bin/bash
for badword in kill bomb steal
do
 for file in `find .`
 do
   if [ `grep -c -h $badword "$file"` -ne 0 ]
   then
    uname='do the name cut here from file'
    word=$badword
    loc=$file
   fi
 done
done


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd October 2017 - 11:07 PM