Created
May 1, 2014 05:05
-
-
Save aleks-mariusz/56f5cf06adf3fce7a337 to your computer and use it in GitHub Desktop.
A wise duck once told me, 'Work smarter, not harder!" (if this reference eludes you: http://youtu.be/8jEZraf0eDI) and so i have always loved the 'pconsole' utility, which lets you multiplex your keystrokes to several sessions (presumably into different systems, aka parallel-console's name). But setting up xterms for each session is such a chore,…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/ms/dist/perl5/PROJ/core/5.8/bin/perl | |
# | |
# Last edited by: $Author: koramari $ | |
# on: $Date: 2010/05/28 21:33:24 $ | |
# Revision: $Revision: 1.5 $ | |
# | |
# ID: $Id: pcon.pl,v 1.5 2010/05/28 21:33:24 koramari Exp koramari $ | |
# | |
# this script opens up xterms and attaches pconsole to those xterms | |
$| = 1; | |
use strict; | |
use Time::HiRes qw/sleep/; | |
my @pconsoleHost; # list of hosts (from stdin/cmd line) | |
my @pconsoleTTY; # list of ttys associated with | |
my $progName = ($0 =~ m#^.+/([^/]+)$#)[0]; | |
my $ttyListFile = "/var/tmp/.pcon.$$"; | |
my $pconsolePath="/v/global/user/k/ko/koramari/bin/pconsole"; | |
my $xtermOpt = "-fg white -bg black -fn lucidasanstypewriter-8"; | |
my $xtermAction = "ssh"; # what to run in the xterms | |
if ($progName =~ /mpcon/) { $xtermAction = "mconsole"; } | |
die "Cant start pconsole" unless -x $pconsolePath; | |
# | |
# get list of systems, from the command line | |
# | |
if ($#ARGV > 0) { | |
@pconsoleHost = @ARGV; | |
} else { # or from standard input | |
while (<>) { chomp; push @pconsoleHost, split /\s+/; } | |
# since our loop ends at EOF and closes STDIN, we have to re-open it for pconsole to work | |
close STDIN; open STDIN, '<', '/dev/tty' or die "Can't read from /dev/tty: $!\n"; | |
} | |
unless (scalar(@pconsoleHost)) { | |
print "No systems specified (check what was passed on stdin or command line params)\n"; | |
exit; | |
} | |
print "Pconsole needs to run as root (via sudo).. We'll attempt to cache sudo credentials here if needed.. \n"; | |
system("sudo echo"); # cache sudo credentials | |
unlink $ttyListFile if -f $ttyListFile; | |
my $geoItr = &screenPositionIterator(scalar(@pconsoleHost)); #exit; | |
print "Found ".scalar(@pconsoleHost)." systems to pconsole.. opening ".scalar(@pconsoleHost)." xterms"; | |
# | |
# in reverse order so first host appear at the top since windows opened in backwards order | |
# | |
foreach my $currHost (reverse @pconsoleHost) { | |
system("xterm $xtermOpt -g ".$geoItr->()." -e 'tty>>$ttyListFile;$xtermAction $currHost' &"); | |
print "."; sleep 0.25; # pause for the creation of the window | |
} | |
print " done!\n"; | |
print "Reading in list of tty's"; | |
do { | |
print "."; sleep 0.333; # sleep for a third of the second before continuing | |
open TTYLIST, $ttyListFile || die "Cant get list of ttys opened: $!"; | |
@pconsoleTTY = map { chomp; $_ } <TTYLIST>; close TTYLIST; | |
unlink $ttyListFile; | |
} while ($#pconsoleTTY < $#pconsoleHost); | |
print "found ".scalar(@pconsoleTTY)." tty's\n\n"; | |
print "Launching "; | |
exec("sudo $pconsolePath ".join(" ",@pconsoleTTY)); | |
sub screenPositionIterator { | |
my ($numWindow) = shift; | |
return undef unless $numWindow; | |
my $numScreen = 3; # number of screens with which to draw xterms | |
$numScreen = 2 if $numWindow <= 24; | |
$numScreen = 1 if $numWindow <= 12; | |
$numScreen = $1 if $0 =~ /pcon(\d+)$/; | |
my ($limitTop,$limitBottom) = (0,714); # usable screen limits | |
my ($sizeX,$sizeY) = (428,282); # size of window in pixels | |
my $numSlot = ( # we want a | |
$numWindow % $numScreen == 0 ? | |
$numWindow : | |
$numScreen * (1+int($numWindow / $numScreen)) | |
); | |
my $numColPerScreen = 3; # didn't want to calculate this based on screen res, so hard coded | |
my $numCol = $numColPerScreen * $numScreen; #$numSlot / $numScreen; | |
my $numRow = ( $numSlot <= $numCol ? 1 : ( | |
$numSlot % $numCol == 0 ? | |
int($numSlot / $numCol)-1 : | |
int($numSlot / $numCol) | |
) | |
); | |
my $incrX = $sizeX; | |
my $incrY = ($limitBottom-$limitTop)/$numRow; | |
$incrY = $sizeY if $incrY > $sizeY; | |
my ($windowX,$windowY); | |
my $currWindow = 1; | |
# print "nW:$numWindow nS:$numSlot nC:$numCol nR:$numRow\n"; | |
return sub { | |
return undef if $currWindow > $numWindow; | |
$windowX = ( ($currWindow-1) % $numCol ) * $incrX; | |
$windowY = $limitBottom - int(int(($currWindow-1) / $numCol ) * $incrY); | |
++$currWindow; | |
return "80x24+".$windowX."+".$windowY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment