Merge branch 'master' of defaria.com:/opt/git/clearscm
authorAndrew DeFaria <Andrew@DeFaria.com>
Fri, 3 Mar 2017 03:26:43 +0000 (19:26 -0800)
committerAndrew DeFaria <Andrew@DeFaria.com>
Fri, 3 Mar 2017 03:26:43 +0000 (19:26 -0800)
bin/allmach.sh [new file with mode: 0755]
bin/bigfiles.pl
bin/cygwinSetup.cmd [new file with mode: 0644]
bin/rexec.pl
lib/CmdLine.pm
lib/Rexec.pm
rc/sshconfig

diff --git a/bin/allmach.sh b/bin/allmach.sh
new file mode 100755 (executable)
index 0000000..d4a9ba5
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/bash
+. _DEBUG.sh
+
+################################################################################
+#
+# File:         allmach
+# Description:  Runs an arbitrary command on all machines
+# Author:       Andrew@DeFaria.com
+# Created:      Fri Apr 30 14:17:40 PDT 1999
+# Language:     Bash Shell
+# Modifications:Added trapping of INT so that you can abort a non-responding
+#               machine.
+#
+# (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
+#
+################################################################################
+# Set me to command name
+me=$(basename $0)
+
+if [ -f ~/.rc/set_colors ]; then
+  source ~/.rc/set_colors
+fi
+
+# Set adm_base
+adm_base=${adm_base:-/opt/clearscm}
+
+# Set machines
+machines=${machines:-$adm_base/data/machines}
+
+if [ "$1" = "-f" ]; then
+  shift
+  machines="$1"
+  shift
+fi
+
+if [ "$1" = "-r" ]; then
+  root_ssh=true
+  shift
+fi
+
+if [ ! -f $machines ]; then
+  echo "Unable to find $machines file!"
+  exit 1;
+fi
+
+function trap_intr {
+  echo "${machines[i]}:$cmd interrupted"
+  echo -e "$RED(A)bort$NORMAL $me or $YELLOW(C)ontinue$NORMAL with next machine? \c"
+  read response
+  typeset -l response=$response
+
+  case "$response" in
+    a|abort)
+      echo "Aborting $me..."
+      exit
+    ;;
+  esac
+  echo "Continuing on with the next machine..."
+} # trap_intr
+
+# Build up data arrays. Note this is done because if we ssh while in a pipe
+# Sun will not allow a simple ssh with no command (boo!)
+# Column 1 Machine name
+# Column 2 Model
+# Column 3 OS Version
+# Column 4 ClearCase Version (if applicable)
+# Column 5 Owner (if known)
+# Column 6 Usage (if known)
+#oldIFS=$IFS
+#IFS=":"
+declare -i nbr_of_machines=0
+#sed -e "/^#/d" $machines |
+while read machine; do
+  machines[nbr_of_machines]=$machine
+  let nbr_of_machines=nbr_of_machines+1
+done < <(grep -v ^# $machines)
+
+if [[ -z "$@" ]]; then
+  cmd="# ${YELLOW}<- ssh into machine$NORMAL"
+else
+  cmd="$@"
+fi
+
+# This loop executes the command
+trap trap_intr INT
+declare -i i=0
+while [ $i -lt $nbr_of_machines ]; do
+  export currmachine=${machines[i]}
+  # Execute command. Note if no command is given then the effect is to
+  # ssh to each machine.
+  echo -e "${CYAN}${machines[i]}$NORMAL\c"
+  echo -e ":$cmd"
+  if [ $# -gt 0 ]; then
+    if [ "$root_ssh" = "true" ]; then
+      ssh ${machines[i]} -n -l root "$cmd"
+    else
+      ssh ${machines[i]} -n "$cmd"
+    fi
+  else
+    if [ "$root_ssh" = "true" ]; then
+      ssh ${machines[i]} -l root
+    else
+      ssh ${machines[i]}
+    fi
+  fi
+  let i=i+1
+done
+trap - INT
index ec9f2a2..1918de1 100755 (executable)
@@ -43,7 +43,7 @@ sub Bigfiles {
 
   foreach (@dirs) {
     next if !-d "$_";
-    my $cmd    = "find \"$_\" -xdev -type f -size +$size -exec ls -lLGQ {} \\;";
+    my $cmd    = "find \"$_\" -xdev -type f -size +$size -exec ls -lLG {} \\;";
     my @lines  = `$cmd`;
 
     foreach (@lines) {
@@ -51,7 +51,8 @@ sub Bigfiles {
 
       my %info;
 
-      if (/\S+\s+\d+\s+(\S+)\s+(\d+).*\"\.\/(.*)\"/) {
+      #if (/\S+\s+\d+\s+(\S+)\s+(\d+).*\"\.\/(.*)\"/) {
+      if (/\S+\s+\d+\s+(\S+)\s+\S+ \S+\s+(\d+)\s+\S+\s+\d+\s+\S+\s+(\S+)/){
        $info {user}    = $1;
        $info {filesize}        = $2;
        $info {filename}        = $3;
diff --git a/bin/cygwinSetup.cmd b/bin/cygwinSetup.cmd
new file mode 100644 (file)
index 0000000..4996c01
--- /dev/null
@@ -0,0 +1,20 @@
+@echo off
+
+rem This script sets up Cygwin
+rem We assume that setup.exe is in the path and that it is the appropriate
+rem Cygwin setup
+
+rem set packages=openssh
+set packages=base-cygwin,base-files,bash,bin-utils,bzip2,coreutils,cron,
+curl,cygrunsrv,cygwin,dateutils,diffutils,dos2unix,expect,file,gcc-core,gcc-g++,git,
+grep,hostname,inetutils,less,make,man,man-pages-posix,
+mintty,openssh,openssl,perl,python,rsync,tar,time,wget,which,xload,xterm,
+xorg-server,xorg-server-common,xorg-x11-fonts-dpi75
+set options=-q -l C:\CygwinPkgs -R C:\Cygwin -s http://mirrors.kernel.org 
+
+mkdir C:\CygwinPkgs
+
+echo setup %options% -P %packages%
+setup %options% -P %packages%
+
+if errorlevel 1 ssh-host-config -y
\ No newline at end of file
index b76d4b1..1770744 100755 (executable)
@@ -74,6 +74,7 @@ use POSIX ":sys_wait_h";
 
 use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../clearadm/lib";
 
+use CmdLine;
 use Display;
 use Logger;
 use Rexec;
@@ -228,10 +229,13 @@ for my $machine (@{$opts{machines}}) {
     connectHost $machine;
 
     if ($currentHost) {
-      while () {
-        display_nolf BOLD . YELLOW . "$machine:" . RESET . WHITE;
+      my $cmdline = CmdLine->new ();
+
+      $cmdline->set_prompt (BOLD . YELLOW . "$machine:" . RESET . WHITE);
 
-        $cmd = <STDIN>; 
+      while () {
+        #$cmd = <STDIN>;
+        $cmd = $cmdline->get(); 
 
         unless ($cmd) {
           display '';
@@ -251,4 +255,4 @@ for my $machine (@{$opts{machines}}) {
       } # while
     } # if
   } # if
-} # for
\ No newline at end of file
+} # for
index 40ed702..ed92843 100644 (file)
@@ -146,8 +146,8 @@ the specified file.',
     description => 'Sets a variable. Note that expression can be any valid expression.',
   },
 
-  vars         => {
-    help       => 'vars',
+  vars          => {
+    help        => 'vars',
     description => 'Displays all known variables.',
   },
 
@@ -182,7 +182,7 @@ sub _cmdCompletion ($$) {
   } # for
 
   return;
-}# _cmdCompletion
+} # _cmdCompletion
 
 sub _complete ($$$$) {
   my ($text, $line, $start, $end) = @_;
@@ -192,7 +192,7 @@ sub _complete ($$$$) {
 
 sub _gethelp () {
   my ($self) = @_;
-  
+
   return unless %_cmds;
 
   my $line = $_cmdline->{line_buffer};
@@ -276,7 +276,7 @@ sub _builtinCmds ($) {
   # Search for matches of partial commands
   my $foundCmd;
 
-  foreach (keys %builtin_cmds) {    
+  for (keys %builtin_cmds) {    
     if ($_ eq $cmd) {
       # Exact match - honor it
       $foundCmd = $cmd;
@@ -292,7 +292,7 @@ sub _builtinCmds ($) {
         last;
       } # unless
     } # if
-  } # foreach
+  } # for
 
   # If we found a command, substitute it into line
   if ($foundCmd) {
@@ -392,7 +392,7 @@ sub _interrupt () {
 
   # Free up all of the line state info
   $_cmdline->free_line_state;
-  
+
   # Allow readline to clean up
   $_cmdline->cleanup_after_signal;
 
@@ -400,7 +400,7 @@ sub _interrupt () {
   $_cmdline->on_new_line;
   $_cmdline->{line_buffer} = '';
   $_cmdline->redisplay;
-  
+
   return;
 } # _interrupt
 
@@ -410,36 +410,36 @@ sub _displayMatches ($$$) {
   # Work on a copy... (Otherwise we were getting "Attempt to free unreferenced
   # scalar" internal errors from perl)
   my @Matches;
-  
-  push @Matches, $_ foreach (@$matches);  
+
+  push @Matches, $_ for (@$matches);  
 
   my $match = shift @Matches;
-  
+
   if ($match =~/^\s*(.*) /) {
     $match = $1;
   } elsif ($match =~ /^\s*(\S+)$/) {
     $match = '';
   } # if
-  
+
   my %newMatches;
-  
-  foreach (@Matches) {
+
+  for (@Matches) {
     # Get next word
     s/^$match//;
-    
+
     if (/(\w+)/) {
       $newMatches{$1} = $1;
     } # if
-  } # foreach
-  
+  } # for
+
   my @newMatches = sort keys %newMatches;
 
   unshift @newMatches, $match;
-  
+
   $_cmdline->display_match_list (\@newMatches);
   $_cmdline->on_new_line;
   $_cmdline->redisplay;
-  
+
   return;
 } # _displayMatches
   
@@ -508,10 +508,10 @@ Returns:
   my $me = get_me;
 
   $histfile ||= ".${me}_hist";
-  
+
   error "Creating bogus .${me}_hist file!"
-    if $me eq '-';
-    
+    if $me eq '-' or $me eq '';
+
   unless (-f $histfile) {
     open my $hist, '>', $histfile
       or error "Unable to open $histfile for writing - $!", 1;
@@ -566,7 +566,7 @@ Returns:
     $opts{trace} = 0;
     $ENV{ANSI_COLORS_DISABLED} = 1;
   } # if
-  
+
   return $self;
 } # new
 
@@ -612,9 +612,9 @@ Returns:
     my $prompt = $self->{prompt};
 
     $prompt =~ s/\\\#/$self->{cmdnbr}/g;
-    
+
     use POSIX;
-    
+
     # Term::ReadLine::Gnu restarts whatever system call it is using, such that
     # once we ctrl C, we don't get back to Perl until the user presses enter, 
     # finally whereupon we get our signal handler called. We use sigaction
@@ -622,16 +622,16 @@ Returns:
     # routine. Sure, sigaction poses race conditions, but you'd either be at a
     # prompt or executing whatever command your prompt prompted for. The user
     # has said "Abort that!" with his ctrl-C and we're attempting to honor that.
-    
+
     # Damn Windows can't do any of this
     my $oldaction;
-    
+
     if ($Config{cppflags} !~ /win32/i) {
       my $sigset    = POSIX::SigSet->new;
       my $sigaction = POSIX::SigAction->new (\&_interrupt, $sigset, 0);
-      
+
       $oldaction = POSIX::SigAction->new;
-    
+
       # Set up our unsafe signal handler
       POSIX::sigaction (&POSIX::SIGINT, $sigaction, $oldaction);
     } # if
@@ -660,7 +660,7 @@ Returns:
 
 sub set_cmds (%) {
   my ($self, %cmds) = @_;
-  
+
 =pod
 
 =head2 set_cmds
@@ -698,17 +698,17 @@ Returns:
   %_cmds = %cmds;
 
   # Add in builtins
-  foreach (keys %builtin_cmds) {
+  for (keys %builtin_cmds) {
     $_cmds{$_}{help}        = $builtin_cmds{$_}{help};
     $_cmds{$_}{description} = $builtin_cmds{$_}{description};
-  } # foreach
+  } # for
 
   return;
 } # set_cmds
 
 sub set_prompt ($) {
   my ($self, $prompt) = @_;
-  
+
 =pod
 
 =head2 set_prompt
@@ -789,7 +789,7 @@ Returns:
 
   if ($histfile and -f $histfile) {  
     $self->{histfile} = $histfile;
-    
+
     if ($_haveGnu) {
       # Clear old history (if any);
       $_cmdline->clear_history;
@@ -797,7 +797,7 @@ Returns:
       # Now read histfile
       $_cmdline->ReadHistory ($histfile);
     } # if
-    
+
     # Determine the number of lines in the history file
     open my $hist, '<', $histfile;
 
@@ -903,34 +903,34 @@ Returns:
   $cmd ||= '';
   $cmd =~ s/^\s+//;
   $cmd =~ s/\s+$//;
-  
+
   if ($cmd =~ /^\s*(.+)/) {
     my ($searchStr, $helpFound);
-    
+
     $searchStr = $1;
 
-    foreach (sort keys %_cmds) {
+    for (sort keys %_cmds) {
       if (/$searchStr/i) {
-             $helpFound = 1;
+        $helpFound = 1;
 
         my $cmdcolor = $builtin_cmds{$_} ? color ('cyan') : color ('magenta');
         my $boldOn   = $builtin_cmds{$_} ? color ('white on_cyan') : color ('white on_magenta');
         my $boldOff  = color ('reset') . $cmdcolor;
-         
-        my $cmd  = "$cmdcolor$_";
+
+           $cmd  = "$cmdcolor$_";
            $cmd =~ s/($searchStr)/$boldOn$1$boldOff/g;
            $cmd .= " $_cmds{$_}{parms}"  if $_cmds{$_}{parms};
            $cmd .= color ('reset');
            $cmd .= " - $_cmds{$_}{help}" if $_cmds{$_}{help};
-        
+
         push @help, $cmd;
 
         if ($_cmds{$_}{description}) {
           push @help, "  $_"
-            foreach (split /\n/, $_cmds{$_}{description});
-             } # if
+            for (split /\n/, $_cmds{$_}{description});
+        } # if
       } # if
-    } # foreach
+    } # for
 
     unless ($helpFound) {
       display "I don't know about $cmd";
@@ -938,7 +938,7 @@ Returns:
       return;
     } # if
   } else {
-    foreach (sort keys %_cmds) {
+    for (sort keys %_cmds) {
       my $cmdcolor = $builtin_cmds{$_} ? color ('cyan') : color ('magenta');
 
       my $cmd  = "$cmdcolor$_";
@@ -949,10 +949,10 @@ Returns:
       push @help, $cmd;
 
       if ($_cmds{$_}{description}) {
-             push @help, "  $_"
-        foreach (split /\n/, $_cmds{$_}{description});
+        push @help, "  $_"
+        for (split /\n/, $_cmds{$_}{description});
       } # if
-    } # foreach
+    } # for
   } # if
 
   $self->handleOutput ($cmd, @help);
@@ -1012,7 +1012,7 @@ Returns:
 
     return;
   } # if
-  
+
   my ($file, $start, $end);
 
   if ($action eq 'list') {
@@ -1064,26 +1064,26 @@ Returns:
 
     if ($action eq 'save') {
       unless ($file) {
-       error "Usage: savehist <file> [<start> <end>]";
-       return;
+        error "Usage: savehist <file> [<start> <end>]";
+        return;
       } # unless
 
       if (-f $file) {
-       display_nolf "Overwrite $file (yN)? ";
+        display_nolf "Overwrite $file (yN)? ";
 
-       my $response = <STDIN>;
+        my $response = <STDIN>;
 
-       unless ($response =~ /(y|yes)/i) {
-         display "Not overwritten";
-         return;
-       } # unless
+        unless ($response =~ /(y|yes)/i) {
+          display "Not overwritten";
+          return;
+        } # unless
       } # if
 
       my $success = open $savefile, '>', $file;
 
       unless ($success) {
-       error "Unable to open history file $file - $!";
-       return;
+        error "Unable to open history file $file - $!";
+        return;
       } # unless
     } # if
 
@@ -1093,9 +1093,9 @@ Returns:
       last unless $histline;
 
       if ($action eq 'list') {
-       display "$pos) $histline";
+        display "$pos) $histline";
       } else {
-       print $savefile "$histline\n";
+        print $savefile "$histline\n";
       } # if
     } # for
 
@@ -1193,13 +1193,13 @@ Returns:
 
   if (defined $value) {
     $value = $self->_interpolate ($value);
-    
+
     # Do not call eval if we are setting result - otherwise we recurse
     # infinitely.
     unless ($name eq 'result') {
       no strict;
       $value = $self->{eval} ($value)
-       if $self->{eval};
+        if $self->{eval};
       use strict;
     } # unless
 
@@ -1247,10 +1247,10 @@ Returns:
 =cut
 
   my @output;
-  
+
   push @output, "$_ = $self->{vars}{$_}"
-    foreach (keys %{$self->{vars}});
-    
+    for (keys %{$self->{vars}});
+
   $self->handleOutput ($cmd, @output);
 } # vars
 
@@ -1300,7 +1300,7 @@ Returns:
 =cut
 
   my ($outToFile, $pipeToCmd);
-  
+
   # Handle piping and redirection
   if ($line =~ /(.*)\>{2}\s*(.*)/) {
     $line      = $1;
@@ -1315,21 +1315,21 @@ Returns:
 
   # Store @output
   $self->{output} = \@output;
-  
+
   if ($pipeToCmd) {
     my $pipe;
-    
+
     local $SIG{PIPE} = 'IGNORE';
-    
-    open $pipe, "|$pipeToCmd"
+
+    open $pipe, '|', $pipeToCmd
       or undef $pipe;
-    
+
     # TODO: Not handling the output here. Need open2 and then recursively call
     # handleOutput.
     if ($pipe) {
       print $pipe "$_\n"
-        foreach (@output);
-        
+        for (@output);
+
       close $pipe
         or error "Unable to close pipe for $pipeToCmd - $!";
     } else {
@@ -1339,21 +1339,21 @@ Returns:
     unless ($outToFile) {
       PageOutput @output;
     } else {
-      open my $output, ">$outToFile";
-      
+      open my $output, '>', $outToFile;
+
       if ($output) {
         print $output "$_\n"
-          foreach (@output);
+          for (@output);
 
         close $output;
-      
+
         undef $outToFile;
       } else {
         error "Unable to open $outToFile for writing - $!"
       } # if
     } # unless
   } # if
-  
+
   return;
 } # handleOutput
 
@@ -1428,25 +1428,25 @@ Returns:
     display "$prompt$_" if $CmdLine::opts{trace};
 
     next if /^\s*($|\#)/;
-    
+
     $_ = $self->_interpolate ($_);
-    
+
     # Check to see if it's a builtin
     my ($cmd, $line, $result) = $self->_builtinCmds ($_);
-    
+
     next if $builtin_cmds{$cmd};
 
     no strict;
     $result = $self->{eval} ($line);
     use strict;
-    
+
     if (defined $result) {
       if (ref \$result eq 'SCALAR') {
         PageOutput (split /\n/, $result);
       } else {
         display "Sorry but I cannot display structured results";
       } #  if
-    } # if    
+    } # if
   } # while
 
   $self->{sourcing} = 0;
@@ -1461,6 +1461,8 @@ sub DESTROY {
 
   $_cmdline->WriteHistory ($self->{histfile})
     if $_cmdline and $_haveGnu;
+
+  return;
 } # DESTROY
 
 our $cmdline = CmdLine->new;
index 6db5735..2eecab8 100644 (file)
@@ -239,7 +239,7 @@ sub ssh {
 
   if ($logged_in) {
     # It's always hard to find the prompt. So let's make a distintive one
-    $self->{prompt} = '@@@';
+    $self->{prompt} = "\n@@@";
     $self->{handle} = $remote;
 
     # OK this is real tricky. If we call execute with a command of PS1=@@@
index 46b7b38..2173b64 100644 (file)
@@ -29,12 +29,14 @@ Host eca-rtp-04
 
 Host git-ric
   Hostname git-ccxsw.ric.broadcom.com
-  #User svcccxswgit
   User ccxswbuild
 
 Host git-rtp
   Hostname git-ccxsw.rtp.broadcom.com
-  #User svcccxswgit
+  User ccxswbuild
+
+Host git-sj
+  Hostname git-ccxsw.sj.broadcom.com
   User ccxswbuild
   
 Host jira-dev