Hi
I've got a sql db with a IP column. I want to somehow use that column as a variable in grep so I can get the results like
grep $IP /var/log/auth.log
Many Thanks,
Hi
I've got a sql db with a IP column. I want to somehow use that column as a variable in grep so I can get the results like
grep $IP /var/log/auth.log
Many Thanks,
Maybe a little clunky, but could you extract that column to a file with something like awk, and then use that file as a lookup with the '-f' option of grep?
I don't know much about sql, so maybe it's not so easy to extract columns of data to a file, though.Code:grep -f <lookup_file> /var/log/auth.log
ahh thanks didn't know about -f option
I guess fgrep/grep -F would do it, too
orCode:fgrep "`psql -A -t -q -c 'SELECT ip FROM table;' db_name username`" /var/log/auth.log
Code:fgrep "`mysql -B -r -e 'SELECT ip FROM table;' -u username db_name`" /var/log/auth.log
Last edited by schragge; March 6th, 2013 at 12:29 PM.
Thanks
Bookmarks