Skip to content

Instantly share code, notes, and snippets.

@serf
Created June 1, 2012 12:07
Show Gist options
  • Save serf/2851655 to your computer and use it in GitHub Desktop.
Save serf/2851655 to your computer and use it in GitHub Desktop.
List all hosts in the date subdirectories of a directory.
<form>
<select name="hostname">
<option value="">- Select Host -</option>
<?php
$collector_dir = '/var/tmp/days';
$hosts = array_unique(explode("\n", shell_exec("/bin/ls $collector_dir/*")));
foreach ($hosts as $host) {
if ( strstr($host,"/") ) {
# We don't want the directories
} elseif ( $host == "" ) {
# We don't want blank lines
} else {
echo "<option value='$host'>$host</option>";
}
}
?>
</select>
</form>
@serf
Copy link
Author

serf commented Jun 1, 2012

Given a directory with a top level sub directory for each day, and a directory (or file) for each host in each day subdirectory, list ALL hosts from all day directories.

e.g.:

/var/tmp/days/
/var/tmp/days/20120515/
/var/tmp/days/20120515/host1
/var/tmp/days/20120515/host2
/var/tmp/days/20120516/
/var/tmp/days/20120516/host1
/var/tmp/days/20120516/host3

This will generate a select list with: host1 host2 host3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment