Re:Distributed grep client in Go
by danieldk on Wednesday October 09, 2013 @03:59AM
(#6519930)
This doesn't really particularly safe to me (assuming that exec.Command allows spaces in arguments):
Since you are searching for the expression in just one log file, why not use Go's excellent regexp package?
[ Parent
| on HN ]
It started off as a class assignment where it was required to execute "grep" on whatever shell we were running the program on. That's why, instead of using the regexp package, we went for the above (somewhat shitty) approach. But, that's something I am definitely looking into changing!
You might have to work pretty hard to write a grep that's as good as grep. It pulls a lot of swift moves in the name of speed.
exec.Command doesn't run a shell; it just executes the command. So yes, it's perfectly safe to have spaces and other shell metacharacters in there. Whether or not it's efficient here is another question, of course.
So yes, it's perfectly safe to have spaces and other shell metacharacters in there.
You could (for instance) probe content of system files by passing
-f/some/file
And matching that to the log. If you have some control over the log, you could use this to read content from system files. Of course, it's all indirect, since the file is interpreted as containing regular expressions. But it's certainly not 'perfectly safe'.