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