hostgrep(1)
β¨ hostgrep β print lines matching hostlist β¨
okay bestie, so picture this: you've got a big pile of files, and somewhere in there are lines that mention your hosts. hostgrep is the girl who finds them. she lives in the General Commands Manual section (section 1, iykyk), and honestly? she's iconic for this.
πΈ SYNOPSIS πΈ
hostgrep [OPTION]... HOSTLIST [FILE]...
π DESCRIPTION π
So what she does is: she searches the files for lines that match the hostlist you gave her. And if you hand her no files at all? No stress β she just searches the standard input instead. main character behavior fr.
Here's the tea on how she actually does it, per line:
- For each line, the program tries to find all hostnames and hostlists. π
- Hostlists get expanded into hostnames. (yes, hostlists are little baby hostname generators, we love that for them)
- Then the set of hostnames in the line gets compared to the set of hostnames given by the
HOSTLISTon the command line. - And by default? The line is printed if any hostname from the
HOSTLISTis found in the line. just one match and she's satisfied, lowkey generous π
β¨ OPTIONS β¨
--allβ print a line only if all hostnames in the givenHOSTLISTare found in the line. she's picky now. she wants the whole squad. π--anyβ print a line if any hostname in the givenHOSTLISTis found in the line. this is the default, it's giving chill girl energy π¦-h,--no-filenameβ do NOT show the filename in front of matching lines. this is the default if at most oneFILEis given. honestly when there's only one file it's kinda redundant, she gets it π-H,--with-filenameβ show the filename in front of matching lines. this is the default if two or moreFILESare given. because with multiple files you NEED to know which one snitched π₯-v,--invert-matchβ invert the sense of matching, so she selects the non-matching lines. plot twist! the lines that didn't match are now the ones on stage π-n,--line-numberβ show line number before match. receipts! so you can go back and find exactly where it was π--restrict=REGEXPβ restrict host matching to the part of the line that is matched as group 1 by this regexp. so she only looks in the little pocket of the line you pointed at, not the whole thing. targeted. precise. obsessed π―
π EXAMPLES π
1. search for lines in an accounting file where any of the three hosts is present (as a hostname or part of a hostlist):
hostgrep n[100-102] /var/log/slurm/accounting/2009-02-22
2. search for lines in the accounting files where all of the three hosts are present (as a hostname or part of a hostlist). do not show filenames:
hostgrep -h --all n[100-102] /var/log/slurm/accounting/*
3. search for lines on stdin where nodes in n[1-8] are mentioned in the part of the line that comes before the first colon:
hostgrep --restrict='^([^:]*):' n[1-8]
π BUGS π
The program has a rather naive notion of what constitutes hostnames and hostlist. she's trying her best okay π
and here's the lore drop, bestie, listen up:
- For version 1.21 and earlier, hostnames were allowed to contain exactly upper and lower case
A-Zand the digits0-9. which meant you literally could not grep for names like"rack02-pos13". the hyphen said no entry. so unfair. - From version 1.22, the code dynamically adds additional characters from the hostlist provided on the command line, so that it will work to grep for hostnames containing those characters. character development, literally. she grew. she evolved. periodt. π±
π AUTHOR π
Written by Kent EngstrΓΆm <kent@nsc.liu.se>.
The program is published at http://www.nsc.liu.se/~kent/python-hostlist/
π«Ά SEE ALSO π«Ά
hostlist (1)
The hostlist expression syntax is used by several programs developed at LLNL (https://computing.llnl.gov/linux/), for example SLURM (https://computing.llnl.gov/linux/slurm/) and Pdsh (https://computing.llnl.gov/linux/pdsh.html).
See the HOSTLIST EXPRESSIONS section of the pdsh(1) manual page for a short introduction to the hostlist syntax. go read it, it's short, you got this π§
and that's the whole page, bestie! this one's Version 2.2.1 of the page, and it's the hostgrep(1) manual page we've been vibing with the whole time. thanks for coming to my ted talk πβ¨π
π¦ where this page comes from
- debian trixie: python3-hostlist 2.2.1-2 Β· GPL-2.0-or-later
- ubuntu resolute: python3-hostlist 2.2.1-2 Β· GPL-2.0-or-later
- ubuntu stonking: python3-hostlist 2.2.1-2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms