-#!/bin/sh
-#
-# $HeadURL$
-# $LastChangedRevision$
-# $LastChangedDate$
-# $LastChangedBy$
-#
-
-usage() {
- echo "$0 [hostname] [optional_command]"
- echo ""
- echo "Connects to a remote system and runs 'ksu' to root"
- echo "Runs optional_command if specified, otherwise, launches a shell"
- echo ""
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Getopt::Long;
+
+sub usage {
+ print "$0 [-c command] hostname [hostname2 [...hostnameN]]\n";
+ print "\nConnects to a remote system and runs 'ksu' to root\n";
+ print "Runs command given with -c if specified, otherwise launches bash\n\n";
+}
+
+my( $command, $login, $tty, $quiet );
+
+GetOptions(
+ "c|command=s" => \$command,
+ "login!" => \$login,
+ "quiet!" => \$quiet,
+ "tty!" => \$tty,
+);
+
+my @hosts = @ARGV;
+
+if( ! @hosts ){
+ warn "No hosts provided\n";
+ usage();
+ exit 1;
}
-if [ $# -eq 0 ]; then
- echo "Error: no host specified!" >&2
- usage
- exit 1
-fi
+# If it's undef it's not specified either way on the command line
+$login = 1
+ unless( defined($login) );
-execargs=''
-ADMINPATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
+my $adminpath = "/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin";
-targethost=$1
-shift
+my @ssh_args = qw{ -oForwardX11=no -oForwardX11Trusted=no -oGSSAPIDelegateCredentials=yes -oBatchMode=yes -oForwardAgent=no -oClearAllForwardings=yes };
+my @ksu_args = qw{ -z };
+if( $quiet ){
+ push @ksu_args, "-q";
+}
+
+if( ! $command ){
+ $command = "/bin/bash";
+ if( $login ){
+ $command .= " --login";
+ # Force TTY allocation
+ $tty = 1;
+ }
+}
+
+if( $tty ){
+ push @ssh_args, "-t";
+}
-if [ -n "$1" ]; then
- execargs="-a -c '$@'"
-fi
+push @ksu_args, "-a", "-c", "'$command'";
-ssh -oForwardX11=no -oForwardX11Trusted=no -oGSSAPIDelegateCredentials=yes -t $targethost PATH=$ADMINPATH ksu -z $execargs
+foreach my $host ( @hosts ){
+ my @args = ( "/usr/bin/ssh", @ssh_args, $host, "PATH=$adminpath", "ksu", @ksu_args );
+# print "Running " . join(' ', @args) . "\n";
+ system( @args ) == 0
+ or warn "rksu failed to $host ('" . join(' ', @args) . "': $!\n";
+}
+mh-sysadmin-tools (1.4) unstable; urgency=low
+
+ * rksu: rewrite in perl, make syntax consistent with Sysdev's
+
+ -- Michael Howe <michael@michaelhowe.org> Fri, 29 Mar 2013 20:49:40 +0000
+
mh-sysadmin-tools (1.3) unstable; urgency=low
* with-creds: support the '-a' option
Package: mh-sysadmin-tools
Architecture: all
-Depends: ${misc:Depends}, krb5-user, kstart
+Depends: ${misc:Depends}, krb5-user, kstart, perl
Recommends: rb3
Description: General sysadmin tools as used on the michaelhowe.org systems
This package contains simple scripts that are used for sysadmin work on