Hi Guys,
i have requirement for log monitor shell script as per below
a)grep WARNING or EXCEPTION or SEVERE from log file
b) count the grep results
c)send an email notification for grep results
please help me .
thanks,
Arun
Hey guys,
Something is puzzling me!
I saw someone use the grep in the following way and I'm not sure I understand what it does, and if there's any benefit to using it this way.
Code:
grep X.X.X.X /var/log/log.log | grep -v query
I checked the man file which confirmed that -v is relating to matching non grouping lines (which I'm not sure I fully understand either!) but I don't see any difference in the output of the above command versus the same command without the | grep -v query bit..
Why would you pipe grep into grep unless you were searching for something specific within the search results?
Does query mean something else?
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.txt
What I have no clue is how to start a loop that would do this...
for each line in filename.txt
UNAME=...
LOC=...
TXT=...
echo "Username: $UNAME, Line with bad word found: $TXT, and Path and file name: $LOC. Is this a BAD file? (Y)"
Read YORN
if ["$YORN" = "Y" ]; then
>> (line of text from grep) badfiles.txt
fi
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.
Hi,
I am looking for a simple shell script that allows for sftp to be run from the server to another server (Windows). I would like the script to be passed parameters suchas destination server, Id, password, Directory structure/folder name, file name etc...
Need some help to know how to start with and it would be great if someone help me with any sample sftp shell script
I want to And search grep shell
but It's hard to grep variable
---------------------------------------------------------------
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Ussage: phone searchfor [...searchfor]"
echo "(You didn't tell me what you want to search for )"
else
pass=0
find=""
for idx in $*
do
if [ -n "$idx" ]
then
if [ $pass -eq 0 ]
then
find=$(egrep "$idx" mydata)
pass=1
else
find=$("$find" | grep "$idx")
echo $find
fi
fi
done
if [ -z "$find" ]
then
echo "There is no such thing"
else
echo $find | awk -f display.awk
fi
fi
-----------------------------------------------------
there is one error : command not found
in find=$("$find" | grep "$idx")
how can I grep variable and store it into variable?
hello everyone,
I created a script file (info.sh) in linux centos 6.
location of file is '/etc/init.d/info.sh'
content of file is:
#!/bin/sh
#To get the MAC address
ifconfig | grep HWaddr
#To get the HDD serial no.
hdparm -I /dev/sd? | grep 'Serial\ Number'
#To get the HDD size
hdparm -I /dev/sda |grep "device size"
gave the permission by: chmod 777 /etc/init.d/info.sh
but when i run this file by: /etc/init.d/info.sh
it gives an error like...
-bash: /etc/init.d/info: cannot execute binary file
what should i do?? Actually i have to run this file during boot up..
thanks in advance..
Please tell me for shell script..
I m writing the script.
In that script i written the 1 function and in that function i have to write the contents in existing file
so i write,
cat > /etc/puppet/manifests/init.pp
{
ensure => present,
}
.
But it caanot write the changes in ssh machine
so what i can do in my script?
Please help me...
I've been using this a lot:
find <directory to start search at> -name "<files to search in>" -type f | xargs grep "<string to search for>"
e.g.
find /usr/include -name "*.h" -type f | xargs grep "#define UINT"
now what if I wanted to output the results to a file?
Hi Everyone,
I need some help on my bash script, I'm trying to rename a certain line in a file which might be 1 or more.
IDXCOUNT=`grep -c 'index .* on ' $FILENAME`;
for n in $(eval echo {1..$IDXCOUNT});
do
timestamp=$(date +"%s");
echo "Renaming index idx_$timestamp..";
if [ $n -eq 1 ]; then
sed -i "0,/^index [^)]* on /s/index idx_$timestamp on /" $FILENAME;
My problem is, if the sed target is 2 or more it will generate an idx_$timestamp that will cause duplicate index value when the script finish. My goal is to have the script recognize that when there are multiple index in the file, it will try to rename it one by one.
I'm new to bash so I'm not sure if I explained my issue well but I will appreciate any help!!
Thanks!
Hi,
I have Redhat 5.3 running on my machine. But when I am login through putty it gives me below error.
Without running any grep command I get this error on login and the grep command doesn't work.
login as: root
root@IP's password:
Last login: Mon Feb 16 15:27:55 2015 from IP
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/grep: cannot execute binary file
-bash: /bin/grep: cannot execute binary file
[root@bkpdrill ~]# grep MemTotal /proc/meminfo
-bash: /bin/grep: cannot execute binary file
Hello there. Im stuck on a task.
it`s the task:
Search the file 'data' for all of the lines that contain the pattern 'linux'
and put those lines in the file 'matches'.
You entered: grep "linux" date > matches
Please try again.
I tried lots of variants
1) grep linux date > matches
2) grep 'linux' date > matches
3) grep linux date >> matches
May be something`s wrong with grep command?
I just dont get it >.>; it should work fine. Where is my mistake folks?