PageRenderTime 176ms CodeModel.GetById 166ms app.highlight 3ms RepoModel.GetById 6ms app.codeStats 0ms

/SSHCommand.sh

http://github.com/bububa/MongoHub-Mac
Shell | 45 lines | 19 code | 8 blank | 18 comment | 0 complexity | 6ca79ab06ea112edbee27dd7d963d313 MD5 | raw file
 1#!/usr/bin/expect -f
 2#!/bin/sh
 3
 4# Copyright (C) 2008  Antoine Mercadal
 5# 
 6# This program is free software; you can redistribute it and/or
 7# modify it under the terms of the GNU General Public License
 8# as published by the Free Software Foundation; either version 2
 9# of the License, or (at your option) any later version.
10# 
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15# 
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20set arguments [lindex $argv 0]
21set password [lindex $argv 1]
22
23eval spawn $arguments
24
25match_max 100000
26
27set timeout 1
28#expect  "*yes/no*" {send "yes\r"; exp_continue};
29
30set timeout 30
31expect {
32		"?sh: Error*" {puts "CONNECTION_ERROR"; exit};
33		"*yes/no*" {send "yes\r"; exp_continue};
34		"*Could not resolve hostname*" {puts "CONNECTION_REFUSED"; exit};
35		"*Operation timed out*" {puts "CONNECTION_REFUSED"; exit};
36		"*Connection refused*" {puts "CONNECTION_REFUSED"; exit};
37		"*?assword:*" {	send "$password\r"; set timeout 4;
38						expect "*?assword:*" {puts "WRONG_PASSWORD"; exit;}
39					  };
40}
41
42puts "CONNECTED";
43set timeout -1
44expect eof;
45