0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linuxのシェル技Tips(複数サーバへ同じコマンドを実行)

Posted at

本資料の目的

  • 複数サーバに対して、何かしらのコマンドを実行したい場合のTips。

前提条件

  • コマンドを実行したいサーバへrootユーザ等でログイン可能なサーバから実行すること。
  • コマンドを実行したいサーバへのログインパスワードが同じであること。
  • ホスト名を指定する場合、コマンド実行元サーバから名前解決が可能なこと。
  • sshpassコマンドが利用可能なこと。

実行内容

1行目

  • for list inの後にコマンドを実行したいサーバを入力

2行目

  • do echo $list

3行目

  • sshpass -pの後にコマンドを実行したいサーバのパスワードを入力し、その後に実行したいコマンドを入力

4行目

  • done

実行コマンドイメージ

[root@xxx ~]# for list in 実行ホスト1 実行ホスト2 実行ホスト3
> do
> echo $list
> sshpass -p パスワード ssh $list 実行したいコマンド
> done
例:NICの一覧を取得したい場合
[root@xxx ~]# for list in aaa bbb ccc
> do
> echo $list
> sshpass -p xxx ssh $list lspci | grep Ethernet
> done
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?