Hi, I am new to Linux and the full capabilities of grep, so I'm having some difficulty figuring out how to obtain the information I want. I'm using grep to search if specific servers are listed in my local nameserver like this:
chknsv NSV | egrep 'box1|box2|box3'
Where chknsv is a function to list all items in the nameserver that include substring NSV in the line.
Ideally, what is returned from egrep is a list like this:
$NSV - box1 - 40000 - tcp
$NSV - box2 - 40000 - tcp
$NSV - box3 - 40000 - tcp
(The first column represents Service name, the second Host name, the third Port, and the fourth Protocol)
What I am wondering is how to check what is returned from egrep to make sure that all of the server names I searched for are included? The exit status of the egrep command returns 0 when anything is returned regardless of how many server names I was searching for. So, it would return 0 even if only one or two of the three servers I'm searching for are listed. This kind of scenario is what I'm trying to detect to verify whether or not all of the server names I searched for are active in the nameserver.
I know it can be done with multiple calls to egrep, but that seems really clunky to me - I'm hoping there's a more elegant solution that I'm just unaware of.
Any advice/suggestions would be greatly appreciated! Thanks!
Hey guys well, i killed a user that was ssh into my machine and a googled how to do it, however the command that I used to find he PID was
ps aux | egrep "sshd: [a-zA-Z]+@"
why not just use ps aux | grep sshd?
also can someone decipher what ps aux | egrep "sshd: [a-zA-Z]+@" means? I am not that advanced to understand what I googled on that? Also, is there a good tutorial to teach you those commands in depth like that? And what are they called? the (egrep "sshd: [a-zA-Z]+@") part.
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
If there is one Windows XP feature that I greatly miss in Mint, it is the Search Companion.
I have been struggling with 'grep' in order to create something suitable but with limited success. Take the following problem:-
I wish to interrogate the folder home/dell/Documents/Domestic/Recipes, searching for all files containing the word "mushroom" or "mushrooms", ignoring case. (I can manage the latter. )
Each individual file search should terminate at the first instance of a match and move to the next file. (Recursive, yeh?) Only the file names need to be listed and the output should be paged to allow for easier reading of long lists.
Several different types of file may be involved, including .doc, .odt, .txt .pdf, .htm and .rtf. It would be nice to include all of them in one command. (Wild card behaviour in grep is not entirely predictable - at least not for me.) Running a separate grep command for each different file type would be tedious.
A significant difficulty is that, if grep fails with a syntax, or run-time error, it generally reports the fact but it also has a habit of producing no output, perhaps not returning to the command prompt, whilst sitting inviting the user to decide what to do next. What makes this particularly frustrating is that some file types might not be amenable to a grep search. Text in .txt files and, it would appear, .doc files appears to be searchable but I suspect that .odt files might be more problematic. The snag in such circumstances is trying to interpret grep's response. Does a null return mean that no match was found or that the file format cannot be successfully interrogated? Such failure might not be apparent if the associated file names are simply excluded from the output list.
Apart from grep, is there any other software that would do the job? Sadly LibreOffice Writer seems to be lacking in this area.
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 Gurus,
I am trying to understand the concept of resolve conf and hope to get some understanding.
When reviewing a sample resolv.conf @
http://www.shellhacks.com/en/Setup-D...nf-in-Examples
stumbled on a scenario.
Lets say I have the following in my resolv.conf
less /etc/resolv.conf
search uncc.org uat.uncc.org sit.uncc.org uat2.uncc.org
intranet.uncc.org
nameserver 192.168.0.100
now if I run command, Note: There is no such thing called appserver
Quote:
ping appserver
My Questions:
1 ) How many lookups are being performed. And which domains are being searched ?
2 ) Will the look up go thru all the 5 domains listed against search directive ?
3) When both directives are provided "search" and "nameserver" will the look up happen on both directives and can both directives be used together ?
Help is much appreciated.
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?
Hello everyone,
I recently started using "function" and "case" in linux but I came across a slight problem
My code:
Code:
function Return
{
echo $1
}
case "$1" in
"" ) echo "give parameters please";;
[0-9]* ) echo "No numbers please";;
* ) Return;;
So whenever the first parameter is a simple word I would like it returned, but it seems like there is no returned string (empty space)
Also I know I can just write "echo $1" instead of Return, but I'd like to use a function for this.
Can anyone tell me why the function doesn't return $1? Thanks!
So, I'm new here. Was thrown into the deepend (read: shallow pool) of linux administration of a few centos 6.5 servers in October, and I've been pretty slow on the uptake. Years of Windows administration and desktop support will do that I guess.
So we have qmail on our prod servers that send out messages for our webapps. Postfix failed last night on a prod server, and it occurred to me that it's happened a few times since I've started, and instead of waiting for clients to tell us, I should be more proactive. I came up with/begged/borrowed/stole a quick script to check to see if postscript was running, and if it was, restart it, and contact us. This was to be run from jenkins.
Quote:
if (( $(ps -ef | grep -v grep | grep postfix | wc -l) > 0 ))
then echo 'Mail is up.'
else echo 'Mail is down! Attempting to restart service...'
service postfix restart
fi
The question was then raised about an unresponsive process (zombies!), and I figured it might be a better idea to use postqueue -q, or mailq to either see a Mailbox is empty, or look for fatal if postfix is off or unresponsive. This is where I ran out of coffee and went over the deep end.
To get this to work, I thought it would be a good idea to run two scripts. One to check if the mail queue is empty, and if not, send up a flag. The next was to run a few minutes later to check and see if the mail queue was throwing up a fatal error, and if it was, throw up a second flag, which sent out an email from jenkins. Incidentally, if the mailqueue were clogged, this would also trigger an alert. Our mailqueue doesn't get a lot of traffic.
First command. Returns then and else statement without issue.
Quote:
if ((mailq | grep 'empty') < 0 ); then echo 'Mail is up.'; else echo 'Mail queue is not empty. Please check mail server'; fi
Second one... Not so much.
Quote:
if (mailq | grep 'fatal') < 1; then echo 'Mail is up.'; else echo 'Mail queue is not empty. Please check mail server'; fi
You can probably suss out what I'm trying to do here, even though I'm not doing it right. Any ideas? I know this is newbie stuff, and I appreciate your taking the time to read this people.
If you run this command on your computer, how many active and passive connections openings are you typically supposed to have? Specifically, for a firewalled home PC behind a wifi router/cable modem combination. Can someone explain the purpose of this command?
in my RHEL 4 server , I want to know what ftp server is running but can't find it.
I tried "ps -ef |grep ftp" but no output , chkconfig --list |grep ftp also no output related to ftp , /etc/rc.d/init.d can't find ftp service , ftp localhost is not allow .
when use FileZilla to connect it , it is ok , the ftp should be running , I tried to use "ps -ef |grep ftp" , it pops the following output , would advise what ftp server is running in server ? thanks
Code:
edp 11027 11026 0 12:39 ? 00:00:00 tcsh -c /usr/libexec/openssh/sftp-server
edp 11037 11027 0 12:39 ? 00:00:00 /usr/libexec/openssh/sftp-server
user 11050 7747 0 12:48 pts/2 00:00:00 grep ftp