mirror of
https://github.com/duncs/clusterssh.git
synced 2025-07-03 09:53:23 +00:00
Add in external_command_pipe
Allow for specific commands to be passed into cssh via a command pipe. This will allow for adding in new sessions and retiling existing sessions. More commands may be added over time.
This commit is contained in:
parent
9a4c7714f9
commit
0dbf7c6808
5 changed files with 106 additions and 0 deletions
1
Changes
1
Changes
|
@ -1,6 +1,7 @@
|
||||||
4.10_03 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
4.10_03 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||||
- Fix for multiple range expansion, as in 'h{a,b}{1,2}' (Github issue #97) (Thanks to lazyfrosch)
|
- Fix for multiple range expansion, as in 'h{a,b}{1,2}' (Github issue #97) (Thanks to lazyfrosch)
|
||||||
- Upgrade Perl::Tidy requirement to version 20171214 (Github issue #99) (Thanks to eserte)
|
- Upgrade Perl::Tidy requirement to version 20171214 (Github issue #99) (Thanks to eserte)
|
||||||
|
- Add in 'external command pipe' to allow for some commands being passed in from the command line
|
||||||
|
|
||||||
4.10_02 2017-08-08 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
4.10_02 2017-08-08 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||||
- Include coverage tests in the resources
|
- Include coverage tests in the resources
|
||||||
|
|
|
@ -171,6 +171,22 @@ sub exit_prog() {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
$self->debug( 3, "Exiting via normal routine" );
|
$self->debug( 3, "Exiting via normal routine" );
|
||||||
|
|
||||||
|
if ( $self->config->{external_command_pipe}
|
||||||
|
&& -e $self->config->{external_command_pipe} )
|
||||||
|
{
|
||||||
|
close( $self->{external_command_pipe_fh} )
|
||||||
|
or warn(
|
||||||
|
"Could not close pipe "
|
||||||
|
. $self->config->{external_command_pipe} . ": ",
|
||||||
|
$!
|
||||||
|
);
|
||||||
|
$self->debug( 2, "Removing external command pipe" );
|
||||||
|
unlink( $self->config->{external_command_pipe} )
|
||||||
|
|| warn "Could not unlink "
|
||||||
|
. $self->config->{external_command_pipe}
|
||||||
|
. ": ", $!;
|
||||||
|
}
|
||||||
|
|
||||||
# for each of the client windows, send a kill.
|
# for each of the client windows, send a kill.
|
||||||
# to make sure we catch all children, even when they haven't
|
# to make sure we catch all children, even when they haven't
|
||||||
# finished starting or received the kill signal, do it like this
|
# finished starting or received the kill signal, do it like this
|
||||||
|
@ -1435,6 +1451,35 @@ sub setup_repeat() {
|
||||||
$self->config->{internal_count}
|
$self->config->{internal_count}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# See if there are any commands in the external command pipe
|
||||||
|
{
|
||||||
|
my $ext_cmd;
|
||||||
|
sysread( $self->{external_command_pipe_fh}, $ext_cmd, 400 );
|
||||||
|
if ($ext_cmd) {
|
||||||
|
my @external_commands = split( /\n/, $ext_cmd );
|
||||||
|
for my $cmd_line (@external_commands) {
|
||||||
|
chomp($cmd_line);
|
||||||
|
my ( $cmd, @tags ) = split /\s+/, $cmd_line;
|
||||||
|
$self->debug( 2,
|
||||||
|
"Got external command: $cmd -> @tags" );
|
||||||
|
|
||||||
|
for ($cmd) {
|
||||||
|
if (m/^open$/) {
|
||||||
|
my @new_hosts = $self->resolve_names(@tags);
|
||||||
|
$self->open_client_windows(@new_hosts);
|
||||||
|
$self->build_hosts_menu();
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
if (m/^retile$/) {
|
||||||
|
$self->retile_hosts();
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
warn "Unknown external command: $cmd_line", $/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#$self->debug( 3, "Number of servers in hash is: ", scalar( keys(%servers) ) );
|
#$self->debug( 3, "Number of servers in hash is: ", scalar( keys(%servers) ) );
|
||||||
|
|
||||||
foreach my $svr ( keys(%servers) ) {
|
foreach my $svr ( keys(%servers) ) {
|
||||||
|
@ -2233,6 +2278,44 @@ sub run {
|
||||||
$windows{main_window}->positionfrom('user')
|
$windows{main_window}->positionfrom('user')
|
||||||
; # user puts it somewhere, leave it there
|
; # user puts it somewhere, leave it there
|
||||||
|
|
||||||
|
# set up external command pipe
|
||||||
|
if ( $self->config->{external_command_pipe} ) {
|
||||||
|
|
||||||
|
if ( -e $self->config->{external_command_pipe} ) {
|
||||||
|
$self->debug( 1, "Removing pre-existing external command pipe" );
|
||||||
|
unlink( $self->config->{external_command_pipe} )
|
||||||
|
or die(
|
||||||
|
"Could not remove "
|
||||||
|
. $self->config->{external_command_pipe}
|
||||||
|
. " prior to creation: "
|
||||||
|
. $!,
|
||||||
|
$/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->debug( 2, "Creating external command pipe" );
|
||||||
|
|
||||||
|
mkfifo(
|
||||||
|
$self->config->{external_command_pipe},
|
||||||
|
oct( $self->config->{external_command_mode} )
|
||||||
|
)
|
||||||
|
or die(
|
||||||
|
"Could not create "
|
||||||
|
. $self->config->{external_command_pipe} . ": ",
|
||||||
|
$!
|
||||||
|
);
|
||||||
|
|
||||||
|
sysopen(
|
||||||
|
$self->{external_command_pipe_fh},
|
||||||
|
$self->config->{external_command_pipe},
|
||||||
|
O_NONBLOCK | O_RDONLY
|
||||||
|
)
|
||||||
|
or die(
|
||||||
|
"Could not open " . $self->config->{external_command_pipe} . ": ",
|
||||||
|
$!
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$self->debug( 2, "Setting up repeat" );
|
$self->debug( 2, "Setting up repeat" );
|
||||||
$self->setup_repeat();
|
$self->setup_repeat();
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,8 @@ my %default_config = (
|
||||||
extra_tag_file => '',
|
extra_tag_file => '',
|
||||||
extra_cluster_file => '',
|
extra_cluster_file => '',
|
||||||
external_cluster_command => '',
|
external_cluster_command => '',
|
||||||
|
external_command_mode => '0600',
|
||||||
|
external_command_pipe => '',
|
||||||
|
|
||||||
unmap_on_redraw => "no", # Debian #329440
|
unmap_on_redraw => "no", # Debian #329440
|
||||||
|
|
||||||
|
|
|
@ -675,6 +675,22 @@ would replace the <Alt-n> with the client's name in each window.}
|
||||||
q{Set the initial position of the console - if empty then let the window manager decide. Format is '+<x>+<y>', i.e. '+0+0' is top left hand corner of the screen, '+0-70' is bottom left hand side of screen (more or less).}
|
q{Set the initial position of the console - if empty then let the window manager decide. Format is '+<x>+<y>', i.e. '+0+0' is top left hand corner of the screen, '+0-70' is bottom left hand side of screen (more or less).}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
output '=item external_command_mode = 0600';
|
||||||
|
output $self->loc(q{File mode bits for the external_command_pipe.});
|
||||||
|
|
||||||
|
output '=item external_command_pipe = <null>';
|
||||||
|
output $self->loc(
|
||||||
|
q{Define the full path to an external command pipe that can be written to for controlling some aspects of ClusterSSH, such as opening sessions to more clusters.
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
|
||||||
|
C<< open <tag|hostname> >> - open new sessions to provided tag or hostname
|
||||||
|
|
||||||
|
C<< retile >> - force window retiling
|
||||||
|
|
||||||
|
e.g.: C<< echo 'open localhost' >> /path/to/external_command_pipe >>}
|
||||||
|
);
|
||||||
|
|
||||||
output '=item external_cluster_command = <null>';
|
output '=item external_cluster_command = <null>';
|
||||||
output $self->loc(
|
output $self->loc(
|
||||||
q{Define the full path to an external command that can be used to resolve tags to host names. This command can be written in any language. The script must accept a list of tags to resolve and output a list of hosts (space separated on a single line). Any tags that cannot be resolved should be returned unchanged.
|
q{Define the full path to an external command that can be used to resolve tags to host names. This command can be written in any language. The script must accept a list of tags to resolve and output a list of hosts (space separated on a single line). Any tags that cannot be resolved should be returned unchanged.
|
||||||
|
|
|
@ -88,6 +88,8 @@ Readonly::Hash my %default_config => {
|
||||||
extra_tag_file => "",
|
extra_tag_file => "",
|
||||||
extra_cluster_file => "",
|
extra_cluster_file => "",
|
||||||
external_cluster_command => '',
|
external_cluster_command => '',
|
||||||
|
external_command_mode => '0600',
|
||||||
|
external_command_pipe => '',
|
||||||
|
|
||||||
unmap_on_redraw => "no",
|
unmap_on_redraw => "no",
|
||||||
|
|
||||||
|
@ -547,6 +549,8 @@ console=console
|
||||||
console_args=
|
console_args=
|
||||||
console_position=
|
console_position=
|
||||||
external_cluster_command=
|
external_cluster_command=
|
||||||
|
external_command_mode=0600
|
||||||
|
external_command_pipe=
|
||||||
extra_cluster_file=
|
extra_cluster_file=
|
||||||
extra_tag_file=
|
extra_tag_file=
|
||||||
fillscreen=no
|
fillscreen=no
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue