Bash Shell Scripting need help figuring out processscripting to scan files for homework - JUST WANT DIRECTIONwords and create report
Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me. I am in the 6th week of my first Linux class ever and we are in our few weeks of beginning scripting. I have some ideas of what to do or where to start but not many and no one to bounce any ideas off...we are using UNIX Bash shell so any others I have no clue.
The scenario is that I need a script that searches all my users home directories for bad words. I need the script to report to the screen certain info like username and word found and path. It should ask a user if it is good or bad and if bad be put into a file of list of bad file names, if good remove from list and no longer flagged by the script.
What I have so far is wanting to somehow do a loop. I do know that if I do a grep -r -e kill -e steal /home/*grep -r -e kill -e steal /home/* I get a list of what I need. I also know that the list is separated by delimiters which I can pipe to get a variable for the things I need. I also know that I can put it to a file with a > filename.tx> filename.txt
Next or whatever goes there...sorry if this is crazy I just really need some direction. I am trying to learn so please don't give me the answer...that will do nothing for me and I will not be able to explain the code I came up with.
UPDATE: WHAT I HAVE DONE SO FAR
I want to learn and understand everything I put in my scripts...otherwise I will never truly get UNIX haha...I'm only 6 weeks in so bare with me.
The RequirementsThe Requirements: Create a script to run to look for bad words such as (at the minimum) bomb, kill, our full name separated with a space, quit, and steal. You must run once to report to the screen and find all documents to show 1- Username 2- Line containing bad word and 3- path and filename. We are then supposed to change our script or do something to it so that we know where the files are then to ignore the files with legitimate uses for example kill process or quit a program (removes a flag)
Finally I want to add a line after each line to ask user is this is a good file? I want to add an if statement that if the answer = Y then I can remove the line from badword.txt, I THINK I know how to create the question and if statement just don't know if there is a way to remove a specific line from the document I created...
Like I said I am VERY new to this and don't even know if this way of doing this is right or wrong...Thank you
Bash Shell Scripting need help figuring out process for homework - JUST WANT DIRECTION
Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me. I am in the 6th week of my first Linux class ever and we are in our few weeks of beginning scripting. I have some ideas of what to do or where to start but not many and no one to bounce any ideas off...we are using UNIX Bash shell so any others I have no clue. The scenario is that I need a script that searches all my users home directories for bad words. I need the script to report to the screen certain info like username and word found and path. It should ask a user if it is good or bad and if bad be put into a file of list of bad file names, if good remove from list and no longer flagged by the script. What I have so far is wanting to somehow do a loop. I do know that if I do a grep -r -e kill -e steal /home/* I get a list of what I need. I also know that the list is separated by delimiters which I can pipe to get a variable for the things I need. I also know that I can put it to a file with a > filename.tx
Next or whatever goes there...sorry if this is crazy I just really need some direction. I am trying to learn so please don't give me the answer...that will do nothing for me and I will not be able to explain the code I came up with.
UPDATE: WHAT I HAVE DONE SO FAR
I want to learn and understand everything I put in my scripts...otherwise I will never truly get UNIX haha...I'm only 6 weeks in so bare with me.
The Requirements: Create a script to run to look for bad words such as (at the minimum) bomb, kill, our full name separated with a space, quit, and steal. You must run once to report to the screen and find all documents to show 1- Username 2- Line containing bad word and 3- path and filename. We are then supposed to change our script or do something to it so that we know where the files are then to ignore the files with legitimate uses for example kill process or quit a program (removes a flag)
Finally I want to add a line after each line to ask user is this is a good file? I want to add an if statement that if the answer = Y then I can remove the line from badword.txt, I THINK I know how to create the question and if statement just don't know if there is a way to remove a specific line from the document I created...
Like I said I am VERY new to this and don't even know if this way of doing this is right or wrong...Thank you
Bash scripting to scan files for words and create report
Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me.
The scenario is that I need a script that searches all my users home directories for bad words. I need the script to report to the screen certain info like username and word found and path. It should ask a user if it is good or bad and if bad be put into a file of list of bad file names, if good remove from list and no longer flagged by the script.
What I have so far is wanting to somehow do a loop. I do know that if I do a grep -r -e kill -e steal /home/* I get a list of what I need. I also know that the list is separated by delimiters which I can pipe to get a variable for the things I need. I also know that I can put it to a file with a > filename.txt
Next or whatever goes there...
The Requirements: Create a script to run to look for bad words such as (at the minimum) bomb, kill, our full name separated with a space, quit, and steal. You must run once to report to the screen and find all documents to show 1- Username 2- Line containing bad word and 3- path and filename. We are then supposed to change our script or do something to it so that we know where the files are then to ignore the files with legitimate uses for example kill process or quit a program (removes a flag)
Finally I want to add a line after each line to ask user is this is a good file? I want to add an if statement that if the answer = Y then I can remove the line from badword.txt, I THINK I know how to create the question and if statement just don't know if there is a way to remove a specific line from the document I created.
grep -r -e kill -e Anne -e bomb -e quit -e steal /home/* > /opt/badword.txt
while read line do LOC=echo -e "$line" | cut -d : -f 1 TXT=echo -e "$line" | cut -d : -f 2 UNAME=echo -e "$line" | cut -d "/" -f 3 echo $LOC echo $TXT echo $UNAME done <badword.txt
grep -r -e kill -e Anne -e bomb -e quit -e steal /home/* > /opt/badword.txt while read line do LOC=`echo -e "$line" | cut -d : -f 1` TXT=`echo -e "$line" | cut -d : -f 2` UNAME=`echo -e "$line" | cut -d "/" -f 3` echo $LOC echo $TXT echo $UNAME done <badword.txt "script4" 19L, 382C written [root@AnneCentOS opt]# ./script4 /home/brownb/doc1 hello my name is xxx i am going to plant a bomb brownb /home/brownb/doc2 I want to kill you brownb /home/mammaj/doc67 kill process mammaj /home/mammaj/doc22 Anne needs to go mammaj /home/swiftt/doc I want to steal a bunch of money so i never have to work again swiftt /home/swiftt/doc300 I want to quit this job! swiftt [root@AnneCentOS opt]#
[root@AnneCentOS opt]# ./script4 /home/brownb/doc1 hello my name is xxx i am going to plant a bomb brownb /home/brownb/doc2 I want to kill you brownb /home/mammaj/doc67 kill process mammaj /home/mammaj/doc22 Anne needs to go mammaj /home/swiftt/doc I want to steal a bunch of money so i never have to work again swiftt /home/swiftt/doc300 I want to quit this job! swiftt [root@AnneCentOS opt]# /home/brownb/doc1:hello my name is xxx i am going to plant a bomb /home/brownb/doc2:I want to kill you /home/mammaj/doc67:kill process /home/mammaj/doc22:Anne needs to go /home/swiftt/doc:I want to steal a bunch of money so i never have to work again /home/swiftt/doc300:I want to quit this job!
/home/brownb/doc1:hello my name is xxx i am going to plant a bomb /home/brownb/doc2:I want to kill you /home/mammaj/doc67:kill process /home/mammaj/doc22:Anne needs to go /home/swiftt/doc:I want to steal a bunch of money so i never have to work again /home/swiftt/doc300:I want to quit this job! grep -r -e kill -e Anne -e bomb -e quit -e steal /home/* > /opt/badword.txt
while read line do LOC=echo -e "$line" | cut -d : -f 1 TXT=echo -e "$line" | cut -d : -f 2 UNAME=echo -e "$line" | cut -d "/" -f 3 echo $LOC echo $TXT echo $UNAME done <badword.txt
"script4" 19L, 382C written [root@AnneCentOS opt]# ./script4 /home/brownb/doc1 hello my name is xxx i am going to plant a bomb brownb /home/brownb/doc2 I want to kill you brownb /home/mammaj/doc67 kill process mammaj /home/mammaj/doc22 Anne needs to go mammaj /home/swiftt/doc I want to steal a bunch of money so i never have to work again swiftt /home/swiftt/doc300 I want to quit this job! swiftt [root@AnneCentOS opt]#
/home/brownb/doc1:hello my name is xxx i am going to plant a bomb /home/brownb/doc2:I want to kill you /home/mammaj/doc67:kill process /home/mammaj/doc22:Anne needs to go /home/swiftt/doc:I want to steal a bunch of money so i never have to work again /home/swiftt/doc300:I want to quit this job!
grep -r -e kill -e Anne -e bomb -e quit -e steal /home/* > /opt/badword.txt while read line do LOC=`echo -e "$line" | cut -d : -f 1` TXT=`echo -e "$line" | cut -d : -f 2` UNAME=`echo -e "$line" | cut -d "/" -f 3` echo $LOC echo $TXT echo $UNAME done <badword.txt [root@AnneCentOS opt]# ./script4 /home/brownb/doc1 hello my name is xxx i am going to plant a bomb brownb /home/brownb/doc2 I want to kill you brownb /home/mammaj/doc67 kill process mammaj /home/mammaj/doc22 Anne needs to go mammaj /home/swiftt/doc I want to steal a bunch of money so i never have to work again swiftt /home/swiftt/doc300 I want to quit this job! swiftt [root@AnneCentOS opt]# /home/brownb/doc1:hello my name is xxx i am going to plant a bomb /home/brownb/doc2:I want to kill you /home/mammaj/doc67:kill process /home/mammaj/doc22:Anne needs to go /home/swiftt/doc:I want to steal a bunch of money so i never have to work again /home/swiftt/doc300:I want to quit this job!