I have installed NS-2.35 in Ubuntu 22.04.1. I am running a TCL code (which is working fine in my friend's machine) but I am getting the following error:
num_nodes is set 101
INITIALIZE THE LIST xListHead
ns: _o1096 Public:
(_o1096 cmd line 1)
invoked from within
"_o1096 cmd Public"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o1096" line 2)
(SplitObject unknown line 2)
invoked from within
"_o1096 Public"
My main tcl file does not have a Public keyword. However, the main file loads another file, in which I have categorized my nodes in three types: public, private and govt.
$ns at 0.0 "[$n49 set ragent_] Public"
#$ns at 0.0 "[$n38 set ragent_] Private"
$ns at 0.0 "[$n59 set ragent_] Govt"
I have 29 Public nodes:
$ns at 0.0 "[$n1 set ragent_] Public"
$ns at 0.0 "[$n2 set ragent_] Public"
$ns at 0.0 "[$n3 set ragent_] Public"
26 Private ones:
$ns at 0.0 "[$n30 set ragent_] Private"
$ns at 0.0 "[$n31 set ragent_] Private"
$ns at 0.0 "[$n32 set ragent_] Private"
Similarly, 2 Govt. nodes:
$ns at 0.0 "[$n58 set ragent_] Govt"
$ns at 0.0 "[$n59 set ragent_] Govt"
But the error is only in Public type. Why so? How do I resolve this error?
Okay. I have finally found a solution.
The problem was with how I was running this code.
After updating AODV and common folder files, I had to recompile the source using the following commands:
> ./configure
> make clean
> make
> sudo make install
This worked for me, I hope it helps other people too.
Related
I was following the below enable fips for mysql
https://dev.mysql.com/blog-archive/openssl-fips-support-in-mysql-8-0/
downloaded these two tars openssl-1.0.2t.tar.gz openssl-fips-2.0.16.tar.gz and tried to build it first into an exe
But running thru lot of issues
The build of FIPS is erroring for missing nmake.dll
mysql blog
C:\openssl\openssl-fips-2.0.16>rem #echo off
C:\openssl\openssl-fips-2.0.16>SET ASM=no--asm
C:\openssl\openssl-fips-2.0.16>SET EXARG=
C:\openssl\openssl-fips-2.0.16>SET MFILE=ntdll.mak
C:\openssl\openssl-fips-2.0.16>if NOT X == X goto wince
C:\openssl\openssl-fips-2.0.16>if NOT XAMD64 == X goto defined
C:\openssl\openssl-fips-2.0.16>if AMD64 == x86 goto X86
C:\openssl\openssl-fips-2.0.16>if AMD64 == IA64 goto IA64
C:\openssl\openssl-fips-2.0.16>if AMD64 == AMD64 goto AMD64
C:\openssl\openssl-fips-2.0.16>echo Auto Configuring for AMD64
Auto Configuring for AMD64
C:\openssl\openssl-fips-2.0.16>SET TARGET=VC-WIN64A
C:\openssl\openssl-fips-2.0.16>if xno--asm == xno-asm goto compile
C:\openssl\openssl-fips-2.0.16>if xno--asm == xno-asm SET EXARG=no-asm
C:\openssl\openssl-fips-2.0.16>perl Configure VC-WIN64A no-asm fipscheck
Configuring for VC-WIN64A
no-asm [option] OPENSSL_NO_ASM
no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128 (skip dir)
no-gmp [default] OPENSSL_NO_GMP (skip dir)
no-jpake [experimental] OPENSSL_NO_JPAKE (skip dir)
no-krb5 [krb5-flavor not specified] OPENSSL_NO_KRB5
no-md2 [default] OPENSSL_NO_MD2 (skip dir)
no-rc5 [default] OPENSSL_NO_RC5 (skip dir)
no-rfc3779 [default] OPENSSL_NO_RFC3779 (skip dir)
no-store [experimental] OPENSSL_NO_STORE (skip dir)
no-zlib [default]
no-zlib-dynamic [default]
IsMK1MF=1
CC =cl
CFLAG =-DOPENSSL_FIPSCANISTER -DOPENSSL_THREADS -DDSO_WIN32 -W3 -Gs0 -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE
EX_LIBS =
CPUID_OBJ =mem_clr.o
BN_ASM =bn_asm.o
DES_ENC =des_enc.o fcrypt_b.o
AES_ENC =aes_core.o aes_cbc.o
BF_ENC =bf_enc.o
CAST_ENC =c_enc.o
RC4_ENC =rc4_enc.o rc4_skey.o
RC5_ENC =rc5_enc.o
MD5_OBJ_ASM =
SHA1_OBJ_ASM =
RMD160_OBJ_ASM=
CMLL_ENC =camellia.o cmll_misc.o cmll_cbc.o
MODES_OBJ =
ENGINES_OBJ =
PROCESSOR =
RANLIB =true
ARFLAGS =
PERL =perl
SIXTY_FOUR_BIT mode
DES_INT used
RC4_CHUNK is unsigned long long
Configured for VC-WIN64A.
WARNING: OpenSSL has been configured to generate a fipscanister.o object module.
That compiled module is NOT FIPS 140-2 validated or suitable for use in
satisfying a requirement for the use of FIPS 140-2 validated cryptography
UNLESS the requirements of the Security Policy are followed exactly (see
http://openssl.org/docs/fips/ or http://csrc.nist.gov/cryptval/).
This is the OpenSSL FIPS 2.0 module.
C:\openssl\openssl-fips-2.0.16>pause
Press any key to continue . . .
C:\openssl\openssl-fips-2.0.16>echo on
C:\openssl\openssl-fips-2.0.16>perl util\mkfiles.pl 1>MINFO
C:\openssl\openssl-fips-2.0.16>perl util\mk1mf.pl dll no--asm VC-WIN64A 1>ms\ntdll.mak
***************************
****FIPS BUILD FAILURE*****
***************************
I am trying to get a value from an instance with OID using tcl command.
In TCL, the command works:
% set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
iso.3.6.1.4.1.31926.2.1.1.19.1 = INTEGER: -57
I am trying to get the number -57 only, so I wrote a tclsh script:
set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
set splitted_result [split $snmp_result ""]
puts [lindex $splitted_result 3]
And then I got error:
invalid command name "snmpwalk"
while executing
"snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19"
invoked from within
"array set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]"
(file "./siklu.tcl" line 1)
I also learned that the tclsh is EEM policy, so I tried:
array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact]
But that gave me this error:
invalid command name "sys_reqinfo_snmp"
while executing
"sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact"
invoked from within
"array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type axact]"
(file "./siklu.tcl" line 2)
You have to use exec command to execute them.
set snmp_result [exec snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
puts $snmp_result
I've run into another strange behavior I can't seem to find an answer for. These are really confusing as I am seeing this problem with the simplest code, which is nearly straight out of the Exploring Expect book. I'm not sure why I'm seeing these issue, and no one else seems to have any problems.
Again, I've boiled this down to a super simple script. If I run it with no arguments, it doesn't fork off the process to a child and kill the parent. If I pass it any argument at all, it will use fork to create a child. When this runs as a parent process, it works normally as expected. But when this runs in the child process, the "expect" command doesn't seem to be connected to anything as it isn't receiving any output from the spawned process. I just don't know enough about what is going on here to be able to debug the problem.
The simple (updated) script:
package require Expect
puts "Tcl version : [info tclversion]"
puts "Expect version: [exp_version]"
# Any passed in argument will enable forking to child process
# fork_cat : Forks and then spawns a process to simply cat a text to stdout
# fork_wish: Forks and then spawns a process to start up wish which opens the
# Tk window as well out the interactive prompt % from the interpreter.
if {$argc > 0} {
while {1} {
# If forking fails, retry every 10 seconds until it succeeds.
if {[catch fork child_pid] == 0} {
break
}
sleep 10
}
if {[lindex $argv 0] == "fork_wish"} {
# Delay so process tree snapshot can be captured with both parent and child processes
sleep 20
}
# Kills the parent process to return terminal control to shell
if {$child_pid != 0} {
puts "[pid] Parent process exiting..."
exit
}
if {[lindex $argv 0] == "fork_wish"} {
# Delay so process tree snapshot can be captured of only child process after parent exits
sleep 20
}
# Redefine exit procedure for child so it kills the process for sure on exit
# I have no idea why exit doesn't work for a child process, but this seems to ensure it goes away on exit.
exit -onexit {
puts "[pid] Killing PID..."
exec kill [pid]
}
}
sleep 1
# Show stty output in case it is relevant to debugging
puts ""
stty -a
puts ""
# Spawn process to cat a text file
switch -exact [lindex $argv 0] {
"fork_cat" {
set spawned_pid [spawn -noecho cat 123.txt]
}
"fork_wish" {
set spawned_pid [spawn -noecho wish]
}
default {
set spawned_pid [spawn -noecho cat 123.txt]
}
}
while {1} {
expect {
eof {
puts ""
puts "[pid] Process received EOF from spawned process"
break
}
timeout {
puts ""
puts "[pid] Process expect timed out for spawned process"
}
}
}
puts ""
puts "[pid] Process exiting..."
exit
Running "cat" without any forking (normal foreground process):
:> temp_eof
Tcl version : 8.4
Expect version: 5.43.0
speed 38400 baud; line = 0;
-brkint ixoff -imaxbel
123
123
123
123
123
15060 Process recieved EOF from spawned process
15060 Process exiting...
Running "cat" without any forking (background process):
:> temp_eof &
[1] 15081
:> Tcl version : 8.4
Expect version: 5.43.0
speed 38400 baud; line = 0;
eof = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; min = 1; time = 0;
-brkint inlcr ixoff -imaxbel
-icanon -iexten -echo -echok
123
123
123
123
123
15081 Process received EOF from spawned process
15081 Process exiting...
[1] + Suspended (tty output) temp_eof
[lc-bun-019: AB: ~/bin]
:> fg
temp_eof
Running "cat" with forking:
:> temp_eof fork_cat
Tcl version : 8.4
Expect version: 5.43.0
15121 Parent process exiting...
:>
speed 38400 baud; line = 0;
eof = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; min = 1; time = 0;
-brkint inlcr ixoff -imaxbel
-icanon -iexten -echo -echok
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
15123 Process expect timed out for spawned process
:> pkill temp_eof
So the question is, why does expect work fine from a normal foregrounded process, but doesn't seem to receive any output from the spawned process when executed from a forked child process? Also not sure why the non-forked backgrounded version is suspending the tty when it exits. But you can now see the similarity of the output from stty in a normally started background process compared to the spawned process started from the forked child process.
I have verified that the spawn command is actually running from the forked child process. I changed the command from cat to something like "touch" that creates a file as evidence it actually was spawned. But either the spawned process has it's output directed somewhere else, or the expect isn't correctly seeing it. My feeling is that it's the former, and that while spawn is succesfully creating a process, it's stdin/stdout maybe be pointing to /dev/null. I am just not experienced enough to debug further. I know enough to get myself into trouble, but apparently not enough to get myself out of it.
I also wanted to capture snapshots of the process tree at 3 points in time. One when the parent and child are both alive. Another when the parent has died, and only the child remains alive. And finally when the child process and it's spawned process are alive. For this I change to spawning something GUI-like that stays open until you X it dead. I thought "wish" was perfect for this. In a separate shell during the 20 second delays, I ran "ps axjf" and redirected into a file. The important parts of that output are shown below the stdout captured below.
First the shell output from this run of "fork_wish":
:> temp_eof fork_wish
Tcl version : 8.4
Expect version: 5.43.0
29172 Parent process exiting...
:>
speed 38400 baud; line = 0;
eof = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; min = 1; time = 0;
-brkint inlcr ixoff -imaxbel
-icanon -iexten -echo -echok
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
29174 Process expect timed out for spawned process
:> pkill temp_eof
First snapshot (both parent and child alive):
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 24566 24564 20131 pts/30 20131 S 9276 0:00 konsole -T Main /dev/null
24566 24569 24569 24569 pts/35 29172 Ss 9276 0:00 \_ -bin/tcsh
24569 29172 29172 24569 pts/35 29172 Sl+ 9276 0:00 | \_ /usr/local/bin/tclsh temp_eof fork_wish
29172 29174 29172 24569 pts/35 29172 S+ 9276 0:00 | \_ /usr/local/bin/tclsh temp_eof fork_wish
24566 26530 26530 26530 pts/36 29175 Ss 9276 0:00 \_ -bin/tcsh
26530 29175 29175 26530 pts/36 29175 R+ 9276 0:00 \_ ps axjf
Second snapshot (child alive, parent dead):
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 24566 24564 20131 pts/30 20131 S 9276 0:00 konsole -T Main /dev/null
24566 24569 24569 24569 pts/35 24569 Ss+ 9276 0:00 \_ -bin/tcsh
24566 26530 26530 26530 pts/36 29176 Ss 9276 0:00 \_ -bin/tcsh
26530 29176 29176 26530 pts/36 29176 R+ 9276 0:00 \_ ps axjf
1 29174 29172 24569 pts/35 24569 S 9276 0:00 /usr/local/bin/tclsh temp_eof fork_wish
Third snapshot (child and spawn alive):
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 24566 24564 20131 pts/30 20131 S 9276 0:00 konsole -T Main /dev/null
24566 24569 24569 24569 pts/35 24569 Ss+ 9276 0:00 \_ -bin/tcsh
24566 26530 26530 26530 pts/36 29192 Ss 9276 0:00 \_ -bin/tcsh
26530 29192 29192 26530 pts/36 29192 R+ 9276 0:00 \_ ps axjf
1 29174 29172 24569 pts/35 24569 S 9276 0:00 /usr/local/bin/tclsh temp_eof fork_wish
29174 29178 29178 29178 pts/37 29178 Ssl+ 9276 0:00 \_ /usr/bin/wish
The thing that looks strange to me here, is that the spawned process has a new, unique, TTY of pty/37, while the child process has a TTY of pty/35 (which matches the tcsh TTY that started it). This is in line with the child still being able to send text to stdout, while the spawened process can't seem to send anything anywhere. Is the unique pts/37 TTY expected for a process spawned from Expect? I thought I remember reading that Expect created a new pseudo-terminal for communication with it's spawned processes. But if that's the case, why is Expect losing communication with it's spawned process connected to pty/37?
I've tried to gather some more clues and information, but something still seems very fishy here. This is pretty much what Expect is designed to do, and the behavior just doesn't seem to be in line with what I understand. Do others see this same behavior if you run my simple example script on your setup?
Thanks in advance for any help or suggestions.
use :
expect_user [expect_args]
is like expect but it reads characters from stdin (i.e.
keystrokes from the user). By default, reading is performed in
cooked mode. Thus, lines must end with a return in order for
expect to see them. This may be changed via stty (see the stty
command below).
instead of expect worked for me.
Really Short Story:
I'm incredibly frustrated by this issue
Short Story:
JRuby-1.7.2 building to a .war using Warbler (1.3.8) deploying to a glassfish v3 server. I can build on my machine and everything works fine, however when I try to build with Jenkins, the war gives the following error when trying to load the first page:
org.jruby.exceptions.RaiseException: (NameError) uninitialized constant ApplicationController::SessionsHelper
Long Story:
Build script on our Jenkins server:
#path to rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Use the correct ruby
rvm use "jruby-1.7.2#webadmin"
# Set "fail on error" in bash
set -e
# build
bundle update
warble compiled war
Error log from Glassfish....which I hope has enough info.
[#|2013-05-31T17:10:14.634-0400|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=19;_ThreadName=Thread-2;|PWC1412: WebModule[null] ServletContext.log():INFO: pool was empty - getting new application instance|#]
[#|2013-05-31T17:10:25.181-0400|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=19;_ThreadName=Thread-2;|PWC1412: WebModule[null] ServletContext.log():An exception happened during JRuby-Rack startup
uninitialized constant ApplicationController::SessionsHelper
--- System
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM 1.6.0_27-b27 [linux-amd64]
Time: 2013-05-31 17:10:25 -0400
Server: GlassFish Server Open Source Edition 3.1.2.2
jruby.home: classpath:/META-INF/jruby.home
--- Context Init Parameters:
com.sun.faces.forceLoadConfiguration = true
com.sun.faces.validateXml = true
public.root = /
rails.env = production
--- Backtrace
NameError: uninitialized constant ApplicationController::SessionsHelper
--- RubyGems
Gem.dir: /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/gems
Gem.path:
/opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/gems
Activated gems:
bundler-1.3.5
rake-10.0.4
i18n-0.6.1
multi_json-1.7.4
activesupport-3.2.13
builder-3.0.4
activemodel-3.2.13
erubis-2.7.0
journey-1.0.4
rack-1.4.5
rack-cache-1.2
rack-test-0.6.2
hike-1.2.2
tilt-1.4.1
sprockets-2.2.2
actionpack-3.2.13
mime-types-1.23
polyglot-0.3.3
treetop-1.4.12
mail-2.5.4
actionmailer-3.2.13
arel-3.0.2
tzinfo-0.3.37
activerecord-3.2.13
activeresource-3.2.13
gyoku-1.0.0
nokogiri-1.5.9-java
akami-1.2.0
bcrypt-ruby-3.0.1-java
sass-3.2.9
bootstrap-sass-2.3.1.2
will_paginate-3.0.4
bootstrap-will_paginate-0.0.9
bouncy-castle-java-1.5.0147
coffee-script-source-1.6.2
execjs-1.4.0
coffee-script-2.2.0
rack-ssl-1.3.3
json-1.8.0-java
rdoc-3.12.2
thor-0.18.1
railties-3.2.13
coffee-rails-3.2.2
faker-1.1.2
httpi-2.0.2
jquery-rails-2.2.2
jruby-openssl-0.8.8
nori-2.1.0
rails-3.2.13
sass-rails-3.2.6
wasabi-3.1.0
savon-2.2.0
therubyrhino_jar-1.7.4
therubyrhino-2.0.2
uglifier-1.0.4
uuidtools-2.1.4
--- Bundler
Bundler.bundle_path: /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/gems
Bundler.root: /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF
Gemfile: /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/Gemfile
Settings:
gemfile = /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/Gemfile
without = development:test:assets
bin_path = /opt/glassfish3/glassfish/domains/myDomain/applications/web-admin/WEB-INF/gems/gems/bundler-1.3.5/bin/bundle
--- JRuby-Rack Config
compat_version =
default_logger = org.jruby.rack.logging.StandardOutLogger#62a49a04
equals =
err = com.sun.common.util.logging.LoggingOutputStream$LoggingPrintStream#7a21bdb8
filter_adds_html = true
filter_verifies_resource = false
ignore_environment = false
initial_memory_buffer_size =
initial_runtimes =
jms_connection_factory =
jms_jndi_properties =
logger = org.jruby.rack.logging.ServletContextLogger#19a2312c
logger_class_name = servlet_context
logger_name = jruby.rack
maximum_memory_buffer_size =
maximum_runtimes =
num_initializer_threads =
out = com.sun.common.util.logging.LoggingOutputStream$LoggingPrintStream#52f8d395
rackup =
rackup_path =
rewindable = true
runtime_arguments =
runtime_environment =
runtime_timeout_seconds =
serial_initialization = false
servlet_context = org.apache.catalina.core.ApplicationContextFacade#16c7e149
throw_init_exception = false
|#]
[#|2013-05-31T17:10:25.182-0400|INFO|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=19;_ThreadName=Thread-2;|PWC1412: WebModule[null] ServletContext.log():DEBUG: resetting rack response due exception|#]
Turns out it was an issue with source code control. My helpers directory was not added and therefore Jenkins was not including in the build. Always check the obvious first, if it says it isn't there it probably isn't.
I want to automate the following interaction using Tcl/expect
[root#mgmt NAS]# ssh -q -p 8022 -l user 10.1.1.1
Password:
HP Network Automation Version 9.10.02
Type "HELP connect" to see how to connect to a device.
Type "HELP" to view a list of available commands.
NA>connect 10.1.1.2
WARNING: You do not have an approved reservation for this device at this time.
Attempting to connect to device bigip1.network.company.net (10.1.1.2).
Last login: Wed Sep 26 08:11:42 2012 from 10.2.1.1
Last login: Wed Sep 26 08:11:42 2012 from 10.2.1.1
[root#bigip1:Standby] config #
[root#bigip1:Standby] config #
[root#bigip1:Standby] config #
[root#bigip1:Standby] config # uname -a
Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux
[root#bigip1:Standby] config # exit
logout
Disconnected from device bigip1.network.company.net (10.1.1.2).
NA>quit
Logging out of the NA Proxy Interface.
<Blank Line: couldn't show it with simple formatting>
The user input is essentially:
password
connect 10.1.1.2
uname -a
exit
quit
The script I wrote out, connect.exp, is as follows:
#!/usr/local/bin/expect
# Set the input parameters
set nashost [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set passw [lindex $argv 3]
set device [lindex $argv 4]
set cmd [lindex $argv 5]
set binpath /usr/bin
log_user 0
# Set timeout to 45 seconds
set timeout 45
#check if all were provided
if { $nashost == "" || $port == "" || $user == "" || $passw == "" || $device == "" || $cmd == "" } {
puts "Usage: <nashost> <port> <user> <passw> <device> <command>\n"
exit 1
}
# String Variables
set nasprompt "NA>$"
set prompt "config # $"
# Flag Variables
set running 1
set count 0
# SSH to specified NAS host
if { [catch {spawn $binpath/ssh -q -p $port -o "StrictHostKeyChecking no" -l $user $nashost} error] } {
puts "Spawn: SSH failed: $error"
exit
}
expect {
"assword: " {
send "$passw\r"
incr count
if {$count > 3} {
puts "SSH failed on authentication after 3 tries"
set running 0
} else {
exp_continue
}
}
-re "$nasprompt" {
set running 1
}
"Connection refused" {
puts "$expect_out(buffer)"
set running 0
}
"Offending key" {
puts "Host key verification failed."
set running 0
}
eof {
puts -nonewline "Connection terminated unexpectedly:\n$expect_out(buffer)"
set running 0
}
timeout {
puts "ssh: connect to NAS host $host: Connection timed out"
set running 0
}
}
if {$running == 1} {
send "connect $device\r"
expect {
-re "$nasprompt" {
if {$running > 0} {
puts "connect to Device $device failed:\n$expect_out(buffer)"
}
send "quit\r"
}
-re "$prompt" {
if {$running > 0} {
send "$cmd\r"
set running 0
exp_continue
} else {
puts "$expect_out(buffer)"
send "exit\r"
}
}
full_buffer {
puts "$expect_out(buffer)"
exp_continue
}
eof {
puts "ssh: Connection terminated unexpectedly during command execution: $host."
}
timeout {
puts "ssh: Connection timed out during command execution: $host."
}
}
}
The issue I face is that the output I get for this interaction with this script is inconsistent.
I call the script as follows: expect connect.exp 10.1.1.1 8022 user 'pwd' 10.1.1.2 'uname -a'
Output one:
[root#bigip1:Standby] config #
[root#bigip1:Standby] config # uname -a
Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux
[root#bigip1:Standby] config #
Output two:
<blank line>
<blank line>
u[root#bigip1:Standby] config #
[root#bigip1:Standby] config #
The u at the beginning of line 3 is part of the output, not a typo.
Other variations of output two exist as well.
The output I expected is:
Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux
[root#bigip1:Standby] config #
What am I doing incorrect in my script?
After you send the password, you don't actually wait for the NA prompt before sending the connect command. Change your first expect command to:
set running false
expect {
"assword: " {
incr count
if {$count > 3} {
puts "SSH failed on authentication after 3 tries"
} else {
send "$passw\r"
exp_continue
}
}
"Connection refused" {
puts "$expect_out(buffer)"
}
"Offending key" {
puts "Host key verification failed."
}
eof {
puts -nonewline "Connection terminated unexpectedly:\n$expect_out(buffer)"
}
timeout {
puts "ssh: connect to NAS host $host: Connection timed out"
}
-re "$nasprompt" {
set running true
}
}
if {$running} {
send "connect ...