Last active
December 15, 2015 09:19
-
-
Save amasho/5237181 to your computer and use it in GitHub Desktop.
SSHチェック用スクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl -w | |
| use strict; | |
| use Expect; | |
| use constant SSH_CMD => "ssh -t -o StrictHostKeyChecking=no "; | |
| use constant EXPECT_TIMEOUT => 10; | |
| MAIN:{ | |
| exit if($#ARGV < 0); | |
| open(FI, $ARGV[0]) || die; | |
| while(<FI>){ | |
| chomp(my $server = $_); | |
| next if($server eq ""); | |
| print "check start $server\n"; | |
| my $e = Expect->new; | |
| $e->log_stdout(0); | |
| $e->spawn(SSH_CMD . $server) or die "cannot spawn command"; | |
| $e->expect(EXPECT_TIMEOUT, | |
| [qr/(.*\'s password:)/ => sub{ | |
| sleep(0.5); | |
| shift->send(chr(3)); | |
| print "ok: $server\n"; | |
| exp_continue; | |
| }], | |
| [qr/(.*Connection refused)/ => sub{ | |
| print "error: $server(not connected)\n"; | |
| }], | |
| [qr/(.*or not known)/ => sub{ | |
| print "error: $server(unknown hosts)\n"; | |
| }], | |
| ); | |
| $e->soft_close; | |
| print "check done $server\n"; | |
| } | |
| close(FI); | |
| } | |
| __END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment