Skip to content

Instantly share code, notes, and snippets.

@mcast
Created November 26, 2018 16:54
Show Gist options
  • Save mcast/234972efe61f0cbe9f014978ec145fbf to your computer and use it in GitHub Desktop.
Save mcast/234972efe61f0cbe9f014978ec145fbf to your computer and use it in GitHub Desktop.
quick hack on `ilsresc --tree` to show status for all resources
#!/bin/sh
### Copying: under GPLv3, or other by arrangement with my employer
### Local source: https://gitlab.internal.sanger.ac.uk/CancerIT/cgpDataOut/blob/master/bin/ilsresc-up-the-tree
# This is an ugly bodge,
# it just does what I need
# (iRODS 4.1.12.beta)
#
# i-cgpdev bin/ilsresc-up-the-tree
_main() {
(
ilsresc -l
echo TREE-FOLLOWS
ilsresc --tree --ascii
) | perl -e '
my %res; # key=name, value=status
my $res;
while (<>) {
chomp;
last if $_ eq "TREE-FOLLOWS";
next unless ($k,$v) =
m{^(resource name|status):\s*(.*?)\s*$};
if ($k =~ /^r/) { $res = $v } else { $res{$res} = $v || "(up)" }
}
foreach (values %res) {
s{(down)}{\x1B[31m$1\x1B[00m};
s{(up)}{\x1B[32m$1\x1B[00m};
}
while (<>) {
while (my ($r, $s) = each %res) {
s{(^|^.*? )(\Q$r\E)(:.*?)?\s*$}{sprintf("%-50s %s\n", "$1$2$3", $s)}e;
}
print;
}
'
}
_main
@mcast
Copy link
Author

mcast commented Nov 30, 2018

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