Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In what context ?
For instance, if you want to close the input of standard input, as in "cat > /tmp/input.data", you may use the special << redirection specifier:
Code:
cat > /tmp/input.data <<EOT
Put your input ext here.
You even can use vars to be expanded on the fly, like:
My home dir is $HOME
EOT
In the above, EOT will close the input, as much CTRL^D would.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Hi marozsas
Thanks for the help. In my situation I'm trying to do a grep on an executable file. Particularly, I'm trying to do a wordcount on a particular error named "TA not available".
Lets call the executable term.
Here's what happens...
Quote:
[kinetik@testserver]# term localhost:6916 | grep "TA not available" | wc -l
TA not available
(At this stage, the program just hangs. With this particular executable, to exit you have to use Ctrl+D.)
(...After pressing Ctrl+D)
0
[kinetik@testserver]#
Would your example work in my situation?
EDIT: Sorry I was mistaken, when the executable hangs, not even it's built-in exit command (Ctrl+D) works. I actually have to Ctrl+C it to get back to prompt.
I think its happens because some binary data can hangs your terminal if the terminal driver interprets some of this binary data as commands.
Try to grep only text data. Use the "strings" command to filter non-text data.
Code:
term localhost:6916 | strings | grep "TA not available" | wc -l
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Hi marozsas
I tried your suggestion, no luck I'm afraid. The executable just gets stuck again, then when I do a Ctrl+C it just goes back to prompt, no result this time round.
May be the term program never closes the pipe. It is just waiting to put more data on the pipe....
If I am right, then grep's m option can help. It closes the input after m matching lines.
Code:
term localhost:6916 | strings | grep -m 1 "TA not available" | wc -l
In the above code, the grep will close the standard input after the first match.
I am not sure if this is acceptable to your logic. Otherwise, we must think in another approach. May be putting this piece of code in background and killing it after a while.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Ah man, that nearly looked like it was going to work! Thanks for your help so far marozsas.
Isn't there another way to send the results of the term executable to grep?
I even tried this:
Quote:
grep -m 1 "TA not available" < `term localhost:6916`
I think the problems are a) The term program doesn't output the "TA not available" message to a place where grep actually sees it and b) Isn't there a way to run the term executable to terminate after say 5 seconds?
# create a fifo
mkfifo mypipe
# write to the fifo, in background
term localhost:6916 > mypipe &
# in background, wait 10s, then kill term
( sleep 10; kill `ps -ef | grep "term localhost" | grep -v grep | awk '{print $2}'` ) &
# read the pipe, you have 10s to do that
grep "TA not available" mypipe | wc -l
I don't like this solution. We are pushing hard on this one.
The best solution is term finish itself after a while, or we close the pipe after a number of times, like in "grep -m 1".
Anyway, without more knowledge of term and it's output, I think it is my best shot.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Yeah, I'm a tad hesitent to use that one, as the term program itself is on a pretty important machine. I'm gonna try to copy the term program over to a test machine and give it a go.
Thanks a bunch for your help marozsas, I really appreciate it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.