LoginSignup
2
0

More than 3 years have passed since last update.

csshxを使って複数サーバに同じコマンドを送る

Posted at

色々あって複数のサーバの管理をしているので、アップデート(例えはsudo apt updateとか)作業などはまとめてやりたい。幸いにも私が管理しているサーバば全部Ubuntuに統一しているので、ほとんどの場合は使用するコマンドは同じ。今まではターミナルをたくさん立ち上げて一つずつ手作業でやっていたが、サーバの数が4台を超えたあたりでもう少し効率化をしたくなった。

何かいい方法がないかと調べていて、csshXというのがあるのを知った。他にも似たようなものでpsshmpsshというのがあるらしいが、完全に同じコマンドしかできないので、特にsudoのパスワードが違っていたりすると面倒な気がする。

Macで使う場合はHomebrewでインストールできる。

$ brew install csshX

あとは、使うサーバを列挙してsshでログインすると適当にタイルした端末をたくさん立ち上げてくれる。

$ csshX server1 server2 server3 server4

事前に~/.ssh/configで色々と設定しておくと楽だが、例えばパスワードがサーバによって違う場合はそれぞれの端末でパスワードを打てば良い。

ところで、このcsshXがMacのBigSurではバグがあるらしく動かなかった。

$ csshX server1 server2 server3 server4
Unimplemented: POSIX::tmpnam(): use File::Temp instead at /System/Library/Perl/5.30/darwin-thread-multi-2level/POSIX.pm line 185.
Unimplemented: POSIX::tmpnam() at /usr/local/bin/csshX line 1130.
BEGIN failed--compilation aborted at /usr/local/bin/csshX line 1130.

https://stackoverflow.com/questions/64837097/cant-make-csshx-working-on-mac-os-big-sur
に解決策が書いてあった。というか、エラーメッセージそのものだけど、/usr/local/bin/csshX実体は/usr/local/Cellar/csshx/0.74/bin/csshXの1130行目を指示通り書き換えれば良い。ちなみにこのファイルは書き込み禁止になっているので、chmod -w /usr/local/Cellar/csshx/0.74/bin/csshXとしないと書き換えられない。

/usr/local/Cellar/csshx/0.74/bin/csshX
#==============================================================================#

package CsshX::Launcher;

use base    qw(CsshX::Socket::Selectable);
# use POSIX   qw(tmpnam);
use File::Temp   qw(tmpnam);
Use FindBin qw($Bin $Script);;

これで動いた。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0