1
0

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.

hostsに書かれてる全台がいつから起動してるかワンライナー

1
Last updated at Posted at 2019-12-05
./pssh-2.3.1/bin/pssh -x "-oStrictHostKeyChecking=no"\
 -H "`cat /etc/hosts |\
 awk '{if( $1 != "#" && length($2) > 0 ){print $2 }}'`"\
 -i 'date --date=@$(expr `date +%s` \
- `cut -d "." -f 1 /proc/uptime`)'
 $ ./pssh-2.3.1/bin/pssh -H "`cat /etc/hosts | awk '{if( $1 != "#" && length($2) > 0 ){print $2 }}'`" -i 'date --date=@$(expr `date +%s` - `cut -d "." -f 1 /proc/uptime`)'
[1] 20:28:47 [SUCCESS] localhost.localdomain
Thu May 16 03:35:37 JST 2019
[2] 20:28:47 [SUCCESS] localhost6.localdomain6
Thu May 16 03:35:37 JST 2019
[3] 20:28:47 [SUCCESS] my-service-web001
Thu Jun 13 02:42:48 JST 2019
[4] 20:28:47 [SUCCESS] my-service-web002
Thu Jun 13 01:51:44 JST 2019
...

PSSH : https://code.google.com/archive/p/parallel-ssh/downloads
( wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/parallel-ssh/pssh-2.3.1.tar.gz して解凍してる)

dateの部分は https://qiita.com/todaemon/items/82edbad20e37039d5162 を使わせていただきました。

ちなみに ./pssh-2.3.1/bin/pssh の後に -x "-t -t -oStrictHostKeyChecking=no" ってつけておくと、sudo もできるし、初めてのホストでも通るので便利です。

PSSH (古い)の代わりになるソリューションがあればお知らせください。(for で ssh する … だと長いのでpsshくらい簡潔にできると嬉しいです)

よくあるfor ssh 版

for i in `cat /etc/hosts |\
 awk '{if( $1 != "#" && length($2) > 0 ){print $2 }}'`; do\
 echo $i ;\
 ssh -oStrictHostKeyChecking=no $i cat /etc/resolv.conf;\
 done
$ for i in `cat /etc/hosts | awk '{if( $1 != "#" && length($2) > 0 ){print $2 }}'`; do echo $i ; ssh -oStrictHostKeyChecking=no $i cat /etc/resolv.conf; done
localhost.localdomain
nameserver XXX.XXX.XXX.XXX

pssh 以外では、 ansible all -i inventory_file -m shell -a 'echo hoge' も便利 (複雑なコマンドは書きにくいかもだけど) (あとansibleの整備が要る)


https://qiita.com/ystmg/items/951da0746ab0c42f8ccc (hostsの全台のディスク使用率悪い順に並べるワンライナー) に続く

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?