Re: An XARGS question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Yep wrote:
> Is there a way to have xargs or perhaps another tool take a list
> from stdin and put it somewhere besides the last argument?
> 
> Say if i want to get all the offending IPs (bad logins) for a given
> day then i want to take that list and see if its in a file called
> blacklist
> 
> lastb -ai |fgrep "Jul 18" |awk '{print $10 }'|sort|uniq | xargs grep
> ???  blacklist
> 
> where ??? would be where the stdin goes

Using xargs you could use -I{}, e.g.

    lastb -ai | ... | xargs -I{} grep {} blacklist

(You could also replace the pipe to uniq with the -u option to sort.)

Another approach that springs to mind is using a small loop in your
shell.  With bash it could be this:

for ip in $(lastb -ai |fgrep "Jul 18" |awk '{print $10 }'|sort -u); do
    grep $ip blacklist
done

If you're unsure whether the output may contain spaces, then a while
loop may be easier to cope with than changing $IFS.

lastb -ai | ... |sort -u | while read ip; do
    grep "$ip" blacklist
done

- -- 
Todd        OpenPGP -> KeyID: 0xD654075A | URL: www.pobox.com/~tmz/pgp
======================================================================
An election is coming. Universal peace is declared and the foxes have
a sincere interest in prolonging the lives of the poultry.
    -- T.S. Eliot

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: When crypto is outlawed bayl bhgynjf jvyy unir cevinpl.

iG0EARECAC0FAkS9PeomGGh0dHA6Ly93d3cucG9ib3guY29tL350bXovcGdwL3Rt
ei5hc2MACgkQuv+09NZUB1oDSwCfYnYkEMQniKN5n/kpDJ99vE22u04AoPygzgXT
wVblbpv6H9OOuYI7Krm3
=F4tz
-----END PGP SIGNATURE-----


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux