Shell
clusterssh:防止視窗按字母順序排列
我
cssh
在 Debian 10(包clusterssh 4.13.2-2
)上使用。當我連接到多個伺服器時:
cssh foo bar zz aa
cssh 將打開 4 個終端並按字母順序排序**!!!** 這樣我就可以按如下方式在螢幕上訂購視窗:
aa bar foo zz
這是純粹的邪惡!
我怎樣才能保持窗戶的原始順序?perl 程式碼中是否有一些快速修復?
查看近似源,我們可以看到有一個數組
@servers
似乎按照給定的順序保存了原始主機名參數,還有一個雜湊(未排序的字典)%servers
保存了每個主機的所有資訊,由派生自的鍵索引主機名。在open_client_windows中,它似乎是用有序的名稱數組呼叫的,我們創建了每個
%servers
條目。在
retile_hosts()
中,視窗按 給出的順序打開$sort->( keys(%servers) )
,程式碼從這裡開始,因此是您看到的順序。因此,一種可能的解決方案是在每個伺服器條目的額外欄位中保留它的創建順序,然後更改
$sort
函式以便它按此值而不是鍵排序。(更改密鑰會更簡單,但它被大量使用,並且可能會產生未知的後果。)。以下更新檔適用於我的 Fedora 28 版本的
ClusterSSH.pm
. 您可能需要為您的分佈式版本更改此設置。--- usr/share/perl5/vendor_perl/App/ClusterSSH.pm.orig 2022-08-24 10:47:57.937143651 +0200 +++ usr/share/perl5/vendor_perl/App/ClusterSSH.pm 2022-08-24 11:32:43.637808164 +0200 @@ -116,9 +116,12 @@ my $host_menu_static_items; # number of items in the host menu that should # not be touched by build_host_menu my (@dead_hosts); # list of hosts whose sessions are now closed -my $sort = sub { sort @_ }; # reference to our sort function which may later +#my $sort = sub { sort @_ }; # reference to our sort function which may later # be changed in run() if the user has asked for # natural sorting +# sort using original order of cli args +# https://unix.stackexchange.com/a/714683/119298 +my $sort = sub { sort {$servers{$a}{order} <=> $servers{$b}{order}} @_ }; $keysymtocode{unknown_sym} = 0xFFFFFF; # put in a default "unknown" entry $keysymtocode{EuroSign} @@ -667,6 +670,8 @@ #$xdisplay->flush(); # dont flush here, but after all tiling worked out } +# sort using original order of cli args +my $globalorder; sub open_client_windows(@) { my $self = shift; foreach (@_) { @@ -727,6 +732,8 @@ $servers{$server}{port} = $port || ''; $servers{$server}{master} = $self->config->{mstr} || ''; $servers{$server}{master} = $master if ($master); + # sort using original order of cli args + $servers{$server}{order} = ++$globalorder; $self->debug( 2, "Working on server $server for $_" );