-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrwin3xterm.pl
executable file
·136 lines (121 loc) · 3.96 KB
/
rwin3xterm.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl -w
##
## FILE: rwin3.pl
##
## PURPOSE: Open a remote window to the named machine
##
## Mac OS X version
##
## Related Files:
## rwin-data: remote window information, flatfile database (same data file is used by makeBashrc.groovy)
##
##
## /usr/bin/showrgb | less can help you choose colors.
## http://www.color-hex.com/color-names.html
## Or use https://www.allscoop.com/tools/Web-Colors/web-colors.php
## Commas can be inserted into colors for readability: #ff,e8,e8
## Color examples:
## '#bfe'
## '#bbfef8'
## '#bb,fe,f8'
## 'black'
## 'green2'
## 'misty rose'
## 'MistyRose'
## '#bbbbffffffff'
## '#bbbb,ffff,ffff'
my $machinesFile = "$ENV{HOME}/bin/rwin-data";
$linuxUser = 'ktanaka';
$DefaultDomain = '.ngdc.noaa.gov';
$hostCmd = '/usr/bin/host';
$sshCmd = '/usr/bin/ssh -Y -o VisualHostKey=yes';
$SavedLines = '-sl 2000';
#$Geom = '-geom 80x40+20+20';
$Geom = '-geom 120x40-20-20';
$Font = '-font "-adobe-courier-medium-r-*-*-18-*-*-*-*-*-iso8859-1"';
$xtermCmd = qq'xterm $Geom $Font $SavedLines -sb -fg "FGCOLOR" -bg "BGCOLOR" -T "NAME" -e $sshCmd ACCESS &';
#$xtermCmd = qq'$sshCmd ACCESS';
$Debugging = 0;
##*****************************************************************************
##
## Set up a hash of machine records from the rwin-data file.
##
## Data structure desired:
## machines{name}:
## S/mRec{}:
## ACCESS => C[] ## machine name ( ".ngdc.noaa.gov" may be omitted)
## AKA => C[] ## Also known as comment
## IP => C[] ## IP address
## FG => C[] ## Foreground text color
## BG => C[] ## Background text color
##*****************************************************************************
my %machines = ();
open (my $datafile, "<$machinesFile") or die "Could not read data file '$machinesFile' $!";
while (not eof($datafile)) {
my $row = readline($datafile);
chomp $row;
next if ($row =~ /^#/); ## Skip comments
next if ($row =~ /^$/); ## Skip blank lines
($name, $access, $aka, $ip, $fg, $bg) = split(/\s*\|\s*/, $row);
print join(' , ', $name, $access, $aka, $ip, $fg, $bg). "\n" if $Debugging;
$mrec = { ## Create a machine record
ACCESS => $access,
AKA => $aka,
IP => $ip,
FG => $fg,
BG => $bg
};
$machines{$name}=$mrec;
}
close $datafile;
if ($Debugging) {
my @machList = (sort keys %machines);
foreach $m (@machList) {
$mrec = $machines{$m};
#print "\nm=$m\n";
#print "machines{$m}{ACCESS}=$machines{$m}{ACCESS}\n";
#print "mrec->{ACCESS}=$mrec->{ACCESS}\n";
printf "%-15s | %-27s | %-20s | %-15s | %-15s | %s\n", $m, $mrec->{ACCESS}, $mrec->{AKA}, $mrec->{IP}, $mrec->{FG}, $mrec->{BG};
}
#exit 0;
}
if (scalar(@ARGV) and not exists($machines{$ARGV[0]})) {
print "Unknown system $ARGV[0]. Choose a number\n";
}
if (not scalar(@ARGV) or not exists($machines{$ARGV[0]})) {
my $i = 1;
my @machList = (sort keys %machines);
foreach $m (@machList) {
printf "%2d: %-15s ", $i, $m;
if (defined $machines{$m}->{AKA}) {
print "($machines{$m}->{AKA})\n";
} else {
print "\n";
}
$i++;
}
print "Choose a system #: ";
$choice = <STDIN>;
exit if ($choice < 1 or $choice > $i);
$choice = $machList[$choice - 1];
} else {
$choice = shift;
}
$lookupHost = $machines{$choice}{ACCESS};
#$lookupHost =~ /.*@(\w+)/ and do {
# $lookupHost = $1;
#};
if ($lookupHost !~ /.(gov|edu|net|org|mil|com)$/) {
$lookupHost .= $DefaultDomain;
}
my $fgcolor = $machines{$choice}{FG};
$fgcolor =~ s/,//g; ## strip out any commas
my $bgcolor = $machines{$choice}{BG};
$bgcolor =~ s/,//g; ## strip out any commas
$xtermCmd =~ s/NAME/$choice/;
$xtermCmd =~ s/FGCOLOR/$fgcolor/;
$xtermCmd =~ s/BGCOLOR/$bgcolor/;
$xtermCmd =~ s/ACCESS/$linuxUser\@$lookupHost/;
print `$hostCmd $lookupHost`;
print"system($xtermCmd)\n" if $Debugging;
system($xtermCmd);