Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/273983

Change subject: Make 'field' / 'fields' shell functions available to everyone
......................................................................

Make 'field' / 'fields' shell functions available to everyone

Both Faidon and Aaron have requested that I make these functions more generally
available.

Bug: T102793
Change-Id: I8f1ea341d63af5161aed88bad604835fb54276cd
---
A modules/base/files/environment/field.sh
M modules/base/manifests/environment.pp
2 files changed, 51 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/83/273983/1

diff --git a/modules/base/files/environment/field.sh 
b/modules/base/files/environment/field.sh
new file mode 100644
index 0000000..ba62e10
--- /dev/null
+++ b/modules/base/files/environment/field.sh
@@ -0,0 +1,45 @@
+if [ -n "$BASH_VERSION" -a -n "$PS1" ]; then
+  # Extract a particular field from separator-delimited input.
+  # For example:
+  #
+  #   field 2 /var/log/apache2/apache2.log
+  #
+  # ..is equivalent to:
+  #
+  #   awk '{ print $2 }' /var/log/apache2/apache2.log
+  #
+  field() {
+    local fieldnum="$1"
+    shift
+    /usr/bin/awk -v field="$fieldnum" '{print $(field)}' "${@}"
+  }
+
+  # Take a line from stdin and show a numbered list of its fields.
+  # This helps you know which numeric index to use (with `field`)
+  # to extract a particular column.
+  #
+  # Example:
+  #
+  #   $ fields /var/log/apache2/other_vhosts_access.log
+  #   1 : 2016-02-29T21:50:05
+  #   2 : 75415
+  #   3 : 10.64.17.9
+  #   4 : proxy-server/200
+  #   5 : 14623
+  #   6 : GET
+  #   7 : http://en.wikipedia.org/wiki/Special:BlankPage
+  #   8 : -
+  #   9 : text/html
+  #   10 : -
+  #   11 : -
+  #   12 : Twisted
+  #   13 : PageGetter
+  #   14 : -
+  #   15 : -
+  #   16 : -
+  #   17 : 10.64.17.9
+  #
+  fields() {
+    /usr/bin/tail -1 "${@:---}" | /usr/bin/awk 'END { for (i = 1; i <= NF; 
i++) printf("%s : %s\n", i, $i) }'
+  }
+fi
diff --git a/modules/base/manifests/environment.pp 
b/modules/base/manifests/environment.pp
index 4549b8b..ad35aaa 100644
--- a/modules/base/manifests/environment.pp
+++ b/modules/base/manifests/environment.pp
@@ -86,6 +86,12 @@
         content => $wikimedia_cluster,
     }
 
+    file { '/etc/profile.d/field.sh':
+        source => 'puppet:///modules/base/environment/field.sh',
+        owner  => 'root',
+        group  => 'root',
+        mode   => '0444',
+    }
 
     ### Core dumps
 

-- 
To view, visit https://gerrit.wikimedia.org/r/273983
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f1ea341d63af5161aed88bad604835fb54276cd
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to