Imported Upstream version 2.7
[ossec-hids.git] / src / agentlessd / scripts / ssh.exp
1 #!/usr/bin/env expect
2
3 # @(#) $Id: ./src/agentlessd/scripts/ssh.exp, 2011/09/08 dcid Exp $
4
5 # Agentless monitoring
6 #
7 # Copyright (C) 2009 Trend Micro Inc.
8 # All rights reserved.
9
10 # This program is a free software; you can redistribute it
11 # and/or modify it under the terms of the GNU General Public
12 # License (version 2) as published by the FSF - Free Software
13 # Foundation.
14
15
16 if {[string compare $pass "NOPASS"] == 0} {
17     source $sshnopasssrc
18     return
19 }
20
21
22 expect {
23     "WARNING: REMOTE HOST" {
24         send_user "\nERROR: RSA host key for '$hostname' has changed. Unable to access.\n"
25         exit 1;
26     }
27     "*sure you want to continue connecting*" {
28         send "yes\r"
29         expect "* password:*" {
30             send "$pass\r"
31             source $sshloginsrc
32         }
33     }
34     "ssh: connect to host*" {
35         send_user "\nERROR: Unable to connect to remote host: $hostname .\n"
36         exit 1;
37     }
38     "no address associated with name" {
39         send_user "\nERROR: Unable to connect to remote host: $hostname .\n"
40         exit 1;
41     }
42     "*Connection refused*" {
43         send_user "\nERROR: Unable to connect to remote host: $hostname .\n"
44         exit 1;
45     }
46     "*Connection closed by remote host*" {
47         send_user "\nERROR: Unable to connect to remote host: $hostname .\n"
48         exit 1;
49     }
50     "* password:*" {
51         send "$pass\r"
52         source $sshloginsrc
53     }
54     timeout {
55         send_user "\nERROR: Timeout while connecting to host: $hostname . \n"
56         exit 1;
57     }
58 }