#!/usr/bin/env expect
-# @(#) $Id: ssh_foundry_diff,v 1.2 2009/06/24 17:06:21 dcid Exp $
# Agentless monitoring
#
# Copyright (C) 2009 Trend Micro Inc.
# All rights reserved.
-#
+#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
-# License (version 3) as published by the FSF - Free Software
+# License (version 2) as published by the FSF - Free Software
# Foundation.
-
if {$argc < 1} {
send_user "ERROR: ssh_pixconfig_diff <hostname> <commands>\n";
exit 1;
}
-
-# NOTE: this script must be called from within /var/ossec for it to work.
+# NOTE: this script must be called from within /var/ossec for it to work
set passlist "agentless/.passlist"
set hostname [lindex $argv 0]
set commands [lrange $argv 1 end]
set pass "x"
set addpass "x"
-set timeout 20
+set timeout 20
if {[string compare $hostname "test"] == 0} {
if {[string compare $commands "test"] == 0} {
}
}
-# Reading the password list.
+# Read the password list
if [catch {
set in [open "$passlist" r]
} loc_error] {
set me [string first "|" $line]
set me2 [string last "|" $line]
set length [string length $line]
-
+
if {$me == -1} {
continue;
}
if {$me == $me2} {
continue;
}
-
+
set me [expr $me-1]
set me2 [expr $me2-1]
-
+
set host_list [string range $line 0 $me]
set me [expr $me+2]
set pass_list [string range $line $me $me2]
}
close $in
-
if {[string compare $pass "x"] == 0} {
send_user "ERROR: Password for '$hostname' not found.\n"
exit 1;
}
-
-# SSHing to the box and passing the directories to check.
+# SSH to the box and pass the directories to check
if [catch {
spawn ssh $hostname
} loc_error] {
}
"* password:*" {
send "$pass\r"
-
+
expect {
"Permission denied" {
send_user "ERROR: Incorrect password to remote host: $hostname .\n"
}
}
-
if {[string compare $addpass ""] != 0} {
- # Going into enable mode.
+ # Go into enable mode
send "enable\r"
expect {
"Password:" {
}
}
-
-# Sending commands
-set timeout 60
+# Send commands
+set timeout 60
send_user "\nSTORE: now\n"
send "skip-page-display\r"
-
-# Excluding uptime from the output
+# Exclude uptime from the output
send "sh run\r"
send "$commands\r"
send "exit\rexit\r"