Redirecting stdion, stdout within an AT command

Hello,
I'm strugling with some redirecting and all help is apreciated.
The following program is working as expected, but the result of the AT command doesn't go to any file.
Thanks in advance for the help.

#!/bin/bash
modem=/dev/ttyUSB1
file=/root/imsi.txt

# print error to stderr and exit unsuccessfully
die() {
    echo "$@" >&2
    exit 1
}

/bin/date

# chat helper. try everything twice.
send_expect() {
    chat -V ABORT ERROR '' "$@" '' || chat -V ABORT ERROR '' "$@" ''
}

# keep modem open, so CD doesn't go low and drop connection
# move terminal to FD3 to avoid redirects on everything else ...
exec 3<&1 >"$modem" <"$modem"

# setup modem options ...
stty -F /dev/ttyUSB1 9600 cs8 -parenb -cstopb

if ! [ -e "$modem" ]; then
    die 'Modem not connected'
fi

if ! send_expect 'AT+GCLI?' 'OK'; then
    die 'Modem not registered'
fi


cat "$file"

# give user idea of success
echo "done" >&3

The output of this program is something like

sh miniteste.sh

Tue  3 Dec 17:08:34 WET 2013

+GCLI: 18
4355,33e2c,29,44
4375,33e3c,26,38
4374,33e21,19,24
4373,33e47,18,23
4658,33e25,18,23
4353,33e17,18,22
4372,33e16,14,14
4359,33e54,13,13
4660,33e2a,11,13
4728,33e1a,13,12
4356,33e35,11,9
4713,33e1e,11,9
4357,33e3e,10,6
4354,33e22,9,5
4736,33e41,8,3
4729,33e3f,8,2
4720,33e45,6,-2
4712,33e50,6,-2

OKdone

My problem is that the text after the AT command doesn't show up on the results file, I tried redirecting at command level and doesn't show up.

Thanks for all the help
CLeitao

What do you mean by 'redirecting at command level'? what exactly did you do, word for word, letter for letter, keystroke for keystroke?

Try redirecting stderr.

./script 2>&1 > filename

Hi
Thanks for the fast help.
I've already tried that, the next example shows What I'm missing

[root@ToshibaNote ~]# ./miniteste.sh 2>&1 >teste.log

+GCLI: 18
4355,33e2c,25,37
4375,33e3c,23,32
4373,33e47,17,21
4374,33e21,18,22
4353,33e17,12,10
4658,33e25,13,13
4728,33e1a,13,13
4372,33e16,12,11
4660,33e2a,7,6
4359,33e54,12,10
4356,33e35,8,2
4713,33e1e,12,10
4354,33e22,9,4
4357,33e3e,7,1
4720,33e45,8,2
4729,33e3f,6,-1
4736,33e41,6,-2
4712,33e50,5,-3

OK
[root@ToshibaNote ~]# cat teste.log
Tue  3 Dec 17:37:25 WET 2013
done

Inside teste.log , there is only the output from date command on line 11 and echo command of the last line, the result from the AT command just shows on the screen and I'm not able to redirect to a file.

if ! send_expect 'AT+GCLI?' 'OK\n'; then
    die 'Modem not registered'
fi

Once again thanks for the help

It may be printing to syslog instead of stderr. Try the -S option for chat.

Worst case, the script utility may be used to capture its output.

HI,
The worst case worked, I was able to get the output to a file.

The command was:

script -c "bash -x miniteste.sh" >> teste.log

Probably not very clean, but works

Thanks for your help
Best Regards
CLeitao