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-----

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux