From bcc334ac986a3ef090340e4e19c29059b8be98cf Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Wed, 11 Apr 2018 21:11:20 -0400 Subject: [PATCH 1/8] Fix miqgrep -i functionality. zgrep needs -e to be the last option passed. SYNOPSIS zgrep [ grep_options ] [ -e ] pattern filename... --- tools/miqssh/miqssh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index 129dc976f45..54b911e4df6 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -159,9 +159,9 @@ function clean_pssh_out { if [ $NAME == 'miqtail' ] then - GREP='grep -e' + GREP='grep' else - GREP='zgrep -e' + GREP='zgrep' fi L='L' @@ -191,6 +191,8 @@ done shift $((OPTIND-1)) +GREP="$GREP -e" + if [[ -z "$TRANSPORT" || -z "$PARALLELISM" ]] then echo "TRANSPORT and/or PARALLELISM not specified, see $DIR/.config." From fcbebe1cfd9d76debc20ce090cc554a9b5d8737a Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Thu, 26 Apr 2018 10:13:04 -0700 Subject: [PATCH 2/8] Fix parameter checking for list mode. Was missed when group was changed to use -g. --- tools/miqssh/miqssh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index 54b911e4df6..c7e6d23f559 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -276,11 +276,14 @@ then echo "Not enough arguments!" usage fi -elif [[ "$2" == "list" && $# -lt 2 ]] +elif [ "$1" == "list" ] then - echo - echo "Not enough arguments!" - usage + if [ $# -ne 1 ] + then + echo + echo "Wrong number of arguments!" + usage + fi elif [[ $NAME == 'miqgrep' || $NAME == "miqtail" ]] then if [[ $# -ne 1 && $# -ne 2 ]] From 74289075d00e0b7371ee89d062cc1c1d2bb03333 Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Fri, 27 Apr 2018 14:58:50 -0700 Subject: [PATCH 3/8] Fix miqgrep with ansible transport. No longer show output during ansible run. Only show ansible looking prompts. --- tools/miqssh/miqssh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index c7e6d23f559..2fc9660a4ab 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -503,9 +503,9 @@ then "miqgrep") if [ -n "$PATTERN" ] then - ansible all -i $HOSTS -f $PARALLELISM -m shell -a "$GREP \"$PATTERN\" $LOG | perl -pe 's/^\/.*?://' | sed -e \"s/^/[\$(hostname -s)] /\"" | tee $TMPFILE + ansible all -i $HOSTS -f $PARALLELISM -m shell -a "$GREP \"$PATTERN\" $LOG | perl -pe 's/^\/.*?://' | sed -e \"s/^/[\$(hostname -s)] /\"" | tee $TMPFILE | perl -ne "print if /^\S+\s\|\s\S+\s\|\src=\d+\s>>\s*$|^\S+\s\|\s\S+\s=>\s\{\s*$/" else - ansible all -i $HOSTS -f $PARALLELISM -m shell -a "$GREP $LOG | perl -pe 's/^\/.*?://' | sed -e \"s/^/[\$(hostname -s)] /\"" | tee $TMPFILE + ansible all -i $HOSTS -f $PARALLELISM -m shell -a "$GREP $LOG | perl -pe 's/^\/.*?://' | sed -e \"s/^/[\$(hostname -s)] /\"" | tee $TMPFILE | perl -ne "print if /\|\src=\d+\s>>/" fi ;; esac From 2e43f41cbe5d43cdf8ed90afdad81fb8b0b7b7dc Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Mon, 30 Apr 2018 14:21:52 -0700 Subject: [PATCH 4/8] Add ability to provide multiple groups to run against. Using comma separated list. --- tools/miqssh/miqhosts.rb | 5 ++++- tools/miqssh/miqssh | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tools/miqssh/miqhosts.rb b/tools/miqssh/miqhosts.rb index 81c453d21a3..83f4dd13c3f 100755 --- a/tools/miqssh/miqhosts.rb +++ b/tools/miqssh/miqhosts.rb @@ -43,7 +43,10 @@ def list_groups(data) # Method to list the servers belonging to the specified group. def list_servers(data, group) - puts data[group.to_sym].join(" ") + groups = group.split(',') + servers = [] + groups.each { |g| servers.push(data[g.to_sym]) } + puts servers.uniq.sort.join(" ") end file = ARGV[0] diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index 2fc9660a4ab..3fa61a379ac 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -44,7 +44,7 @@ groups=$($miqhosts_cmd $miqhosts_file list_groups) function usage_common { echo "DESCRIPTION: $2" echo - echo "USAGE: $NAME [-g group] [-s] $1" + echo "USAGE: $NAME [-g group1[,groupN]] [-s] $1" echo shift 2 echo "DETAILS:" @@ -362,30 +362,20 @@ then exit 1 fi -group_good=false - -for i in $groups -do - if [ "$i" == "$group" ] - then - group_good=true - fi -done - -if [ "$group_good" != "true" ] +if [[ "$QUIET" != 'true' && "$TRANSPORT" != 'pssh' && "$TRANSPORT" != 'ansible' || ( $NAME == 'miqgrep' && $REQUEST == 'true' ) ]] then echo - echo "Group $group not found in $miqhosts_file" - usage fi -if [[ "$QUIET" != 'true' && "$TRANSPORT" != 'pssh' && "$TRANSPORT" != 'ansible' || ( $NAME == 'miqgrep' && $REQUEST == 'true' ) ]] +SERVERS=$($miqhosts_cmd $miqhosts_file list_servers $group) + +if [ -z "$SERVERS" ] then echo + echo "No servers found matching group(s) $group in $miqhosts_file" + usage fi -SERVERS=$($miqhosts_cmd $miqhosts_file list_servers $group) - if [ "$1" == "list" ] then if [ "$QUIET" != 'true' ] @@ -395,7 +385,7 @@ then for i in $SERVERS do echo $i - done + done | sort exit fi From edef62a4c3b7919bd94f825508e8fb13be1a783c Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Mon, 30 Apr 2018 14:48:42 -0700 Subject: [PATCH 5/8] Fix miqcollect to support wildcard with pssh. Previously wildcard would work as long as didn't match local system. This fix prevents wildcard from being matched on local system. --- tools/miqssh/miqssh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index 3fa61a379ac..e83f9a836ec 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -477,7 +477,7 @@ then case $NAME in "miqssh") pssh -t 0 -i $HOSTS $ARGS ;; "miqscp") pscp.pssh -t 0 $HOSTS $1 $2 ;; - "miqcollect") pslurp -t 0 $HOSTS -L $2 $1 . ;; + "miqcollect") pslurp -t 0 $HOSTS -L $2 "$1" . ;; "miqgrep") pssh -t 0 $HOSTS -o $PSSH_OUTDIR "$GREP \"$PATTERN\" $LOG | perl -pe 's/^\/.*?://' | sed -e \"s/^/[\$(hostname -s)] /\"" ;; esac From 1752b703bed10710d513d44364635802a89f45b1 Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Mon, 30 Apr 2018 15:07:48 -0700 Subject: [PATCH 6/8] Fix miqcollect with ansible transport. Ansible fetch doesn't support wildcards, so switch to straight ssh as needed. --- tools/miqssh/miqssh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index e83f9a836ec..faf2147accf 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -193,6 +193,19 @@ shift $((OPTIND-1)) GREP="$GREP -e" +if [[ "$TRANSPORT" == 'ansible' && $NAME == 'miqcollect' ]] +then + wildcards=( '*' '.' '?' '|' ']' '[' ) + for wildcard in "${wildcards[@]}" + do + if [[ $1 == *"${wildcard}"* ]] + then + echo "*** Switching TRANSPORT to ssh due to wild card in source file name ***" + TRANSPORT=ssh + fi + done +fi + if [[ -z "$TRANSPORT" || -z "$PARALLELISM" ]] then echo "TRANSPORT and/or PARALLELISM not specified, see $DIR/.config." From 2ff98ceb489c82f7431396586e65dd777b39acaa Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Mon, 30 Apr 2018 17:33:25 -0700 Subject: [PATCH 7/8] Fix ARGS for Ansible transport. Ansible to become new recommended transport. --- tools/miqssh/miqssh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/miqssh/miqssh b/tools/miqssh/miqssh index faf2147accf..8f3a0bdc747 100755 --- a/tools/miqssh/miqssh +++ b/tools/miqssh/miqssh @@ -458,7 +458,7 @@ then fi ARGS=$* -ARGS=$(echo $ARGS | sed 's/*/\\*/g') +#ARGS=$(echo $ARGS | sed 's/*/\\*/g') if [ $NAME != 'miqtail' ] then From f5edd6d88e20387c2a572d3f23698fc2f88831ec Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Mon, 30 Apr 2018 17:36:28 -0700 Subject: [PATCH 8/8] Update README to reflect Ansible as preferred transport. --- tools/miqssh/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/miqssh/README.md b/tools/miqssh/README.md index 1785b3fe1f8..5b71c3db433 100644 --- a/tools/miqssh/README.md +++ b/tools/miqssh/README.md @@ -4,7 +4,7 @@ These tools allow for running commands and copying files and searching log files Also, even if you do have pssh or other tools for running commands on multiple systems, the new miqgrep, miqgrep -r, miqtail, and miqtail -r are worth a look. -Different transport mechanisms are now supported and can be selected by updating the .config file. By default, Ansible is used since it can work in parallel and is included by default with ManageIQ. Alternatively, if installed and selected, Parallel SSH can be used and is faster opening connections than Ansible. +Different transport mechanisms are now supported and can be selected by updating the .config file. By default, Ansible is used since it can work in parallel and is included by default with ManageIQ. Ansible is now the recommended transport for best functionality. **Note that this program can enable you to do things faster, including mistakes, use at your own risk.**