/usr/bin/expect script truncates data

I have a script on a Linux machine that connects remotely, via telnet on a windows machine to launch several commands and colect their output. On the Linux machine the output of these commands is redirected in a file.

The script:

#!/usr/bin/expect

log_user 0
spawn telnet 10.10.10.10
expect "login name:"
send "user1\r"
expect "password:"
send "Pa$$w0rd@\r"
expect "Windows NT Domain:"
send "\r"
#expect "C:\WINNT\Profiles\focore>"
sleep 1
send "echo prcstate\r"
send "prcstate -l\r"
sleep 1
send "echo hwmls\r"
send "hwmls\r"
sleep 1
send "echo hwmscbls\r"
send "hwmscbls\r"
sleep 1
send "echo cluster res\r"
send "cluster res\r"
sleep 1
send "echo cluster node\r"
send "cluster node\r"
sleep 1
send "echo cluster group\r"
send "cluster group\r"
sleep 1
send "echo cluster netint\r"
send "cluster netint\r"
sleep 1
send "echo mtzln -p\r"
send "mtzln -p\r"
sleep 1
send "echo time /t\r"
send "time /t\r"
sleep 1
send "echo date /t\r"
send "date /t\r"


send "exit\r"
interact
exit

When I launch the script "manually" from the shell

 ./expect.sh > output.txt 

The entire output is capted.
When I schedule the script in crontab no output is capted (probably due to the "interact" part of the script).
When I use a wrapper script which launches expect.sh and schedule the wrapper script in crontab output.txt contains only exactly 4.0 Kb and truncates the output of the commands in expect.sh

 cat wrapper.sh
#!/bin/bash

target_log=/absolute_path/output.txt

rm -f $target_log

/absolute_path/expect.sh >> $target_log

I'm new to expect and I don;t know how to overcome this. I've red about a full_buffer command but didn;t succeed to get the right syntax to implement it in my script.
Any ideas how to overcome this ?

why do you use interact
try change to "interact" to "expect eof" (or just remove "interact" ) and re-try

regards
ygemici

Already tried exactly this. replaced in my script the "interact" line with "expect eof" and it doesn;t work at all neither directly from shell, neither from crontab.

In what way does it "not work"?

Can you write the cronjob entry?
Can see any log in the system cron logs about this job(CMD)

yes. I used this script now :

#!/usr/bin/expect

log_user 0
spawn telnet 10.21.222.222
expect "login name:"
send "focore\r"
expect "password:"
send "pwd\r"
expect "Windows NT Domain:"
send "\r"
sleep 1
send "mml\r"
sleep 1
send "ihalp:epid=all;\r"
sleep 9

send "exit;\r"
sleep 1
send "exit\r"
interact
exit

The crontab entry :

 10 * * * * /absolute_path/script_test.sh > /absolute_path/sample.txt 

Cron logs :

From root@NagiosPM.posteM.it  Wed May 28 09:27:14 2014
Return-Path: <root@NagiosPM.posteM.it>
X-Original-To: mnuser
Delivered-To: mnuser@NagiosPM.posteM.it
Received: by NagiosPM.posteM.it (Postfix, from userid 500)
        id 68B0F121A4A; Wed, 28 May 2014 09:27:14 +0200 (CEST)
From: root@NagiosPM.posteM.it (Cron Daemon)
To: mnuser@NagiosPM.posteM.it
Subject: Cron <mnuser@NagiosPM> /box/monitoring/scripts/CN/CP/script_test.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/box/monitoring>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=mnuser>
X-Cron-Env: <USER=mnuser>
Message-Id: <20140528072714.68B0F121A4A@NagiosPM.posteM.it>
Date: Wed, 28 May 2014 09:27:14 +0200 (CEST)

^MVerifying user credentials. Please wait...
^M
Login ok...

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\WINNT\Profiles\focore^C>mml
WO      PMSSMI1    192020000321   AD-718  TIME 140528 0927  PAGE    1
^C<ihalp:epid=all;
SCTP ASSOCIATION LIST DATA

EPID    EPSTATE         LPN              USER
EM2N2S6 IN SERVICE      3565             M2PA

LIP
10.21.248.214
10.21.248.198

SAID            SASTATE            RPN   OS    MODE
PMSSTP1_M2N2_2  ASSOCESTABL        3566  2     SERVER

RIP                                      RIPSTATE
10.21.238.154                            ACTIVE
10.21.238.146                            ACTIVE

SAID            SASTATE            RPN   OS    MODE
PMSSTO1_M2N2_2  ASSOCESTABL        3566  2     SERVER

RIP                                      RIPSTATE
10.21.224.214                            ACTIVE
10.21.224.198                            ACTIVE

EPID    EPSTATE         LPN              USER
EM2N2S5 IN SERVICE      3565             M2PA

LIP
10.21.248.197
10.21.248.213

SAID            SASTATE            RPN   OS    MODE
PMSSTP1_M2N2_1  ASSOCESTABL        3566  2     SERVER

RIP                                      RIPSTATE
10.21.238.145                            ACTIVE
10.21.238.153                            ACTIVE

SAID            SASTATE            RPN   OS    MODE
PMSSTO1_M2N2_1  ASSOCESTABL        3566  2     SERVER

RIP                                      RIPSTATE
10.21.224.197                            ACTIVE
10.21.224.213                            ACTIVE

EPID    EPSTATE         LPN              USER
EM2N2S4 IN SERVICE      3565             M2PA

LIP
10.21.248.212
10.21.248.196

SAID            SASTATE            RPN   OS    MODE
WSTPRM1_M2N2_2  ASSOCESTABL        3565  2     SERVER

RIP                                      RIPSTATE
10.21.224.83                             NOT ACTIVE
10.21.224.67                             ACTIVE

EPID    EPSTATE         LPN              USER
EM2N2S3 IN SERVICE      3565             M2PA

LIP
10.21.248.195
10.21.248.211

SAID            SASTATE            RPN   OS    MODE
WSTPRM1_M2N2_1  ASSOCESTABL        3565  2     SERVER

RIP                                      RIPSTATE
10.21.224.66                             ACTIVE
10.21.224.82                             ACTIVE

EPID    EPSTATE         LPN              USER
EM2N2S2 IN SERVICE      3565             M2PA

LIP
10.21.248.210
10.21.248.194

SAID            SASTATE            RPN   OS    MODE
WSTPMI1_M2N2_2  ASSOCESTABL        3565  2     SERVER

RIP                                      RIPSTATE
10.21.248.83                             ACTIVE
10.21.248.67                             ACTIVE

EPID    EPSTATE         LPN              USER
EM2N2S1 IN SERVICE      3565             M2PA

LIP
10.21.248.193
10.21.248.209

SAID            SASTATE            RPN   OS    MODE
WSTPMI1_M2N2_1  ASSOCESTABL        3565  2     SERVER

RIP                                      RIPSTATE
10.21.248.66                             ACTIVE
10.21.248.82                             ACTIVE

EPID    EPSTATE         LPN              USER
EM3N3S6 IN SERVICE      2907             M3UA

LIP
10.21.248.214
10.21.248.198

SAID            SASTATE            RPN   OS    MODE
PMGWMI1_M3N3_4  ASSOCESTABL        2907  17    SERVER

RIP                                      RIPSTATE
10.21.249.18                             ACTIVE
10.21.249.2                              ACTIVE

EPID    EPSTATE         LPN              USER
EM3N3S5 IN SERVICE      2907             M3UA

LIP
10.21.248.197
10.21.248.213

SAID            SASTATE            RPN   OS    MODE
PMGWMI1_M3N3_3  ASSOCESTABL        2907  17    SERVER

RIP                                      RIPSTATE
10.21.249.1                              ACTIVE
10.21.249.17                             ACTIVE

EPID    EPSTATE         LPN              USER
EM3N3S4 IN SERVICE      2907             M3UA

LIP
10.21.248.212
10.2

As you can see, in the cron log appears also the output of the script (I don't know why) and the output is truncated exactly after 4Kb. You can see the last line truncated, that is exactly how the output is redirected in my file.

---------- Post updated at 02:52 AM ---------- Previous update was at 02:46 AM ----------

Does not work in the sense that you launch the script, you expect some output but instead nothing happens. The finishes its execution without displaying any errors nor any output

hi black_fender,

add -> "sleep 1" after the ( send "pwd\r" ) wait for auth
remove -> last exit (send "exit\r") unneccessary
remove -> (expect "Windows NT Domain:") unneccessary
change to -> "interact" to ( "expect eof" ) tell to our "expect script", we wait to closed the server's connection and expect programm is over. necessary
if its (expect eof) is not in your script, then your output direction may cannot completed because of expect script is closing without completion processes.
so last view :

#!/usr/bin/expect
log_user 0
spawn telnet 10.21.222.222
expect "login name:"
send "focore\r"
expect "password:"
send "pwd\r"
sleep 1
send "mml\r"
sleep 1
send "ihalp:epid=all;\r"
sleep 9
send "exit;\r"
sleep 1
expect eof
exit

regards
ygemici