Redirecting stdion, stdout within an AT command


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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.
Code:
#!/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
Code:
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

Last edited by Don Cragun; 12-03-2013 at 02:17 PM.. Reason: Add CODE tags.
# 2  
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.
Code:
./script 2>&1 > filename

# 3  
Already done

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

Code:
[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.

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

Once again thanks for the help

Last edited by Corona688; 12-03-2013 at 02:50 PM..
# 4  
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.
# 5  
HI,
The worst case worked, I was able to get the output to a file.

The command was:

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

Probably not very clean, but works

Thanks for your help
Best Regards
CLeitao

Last edited by Scott; 12-03-2013 at 04:21 PM.. Reason: Code tags, please...
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #527
Difficulty: Medium
ASCII was originally developed in the early 1940s.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Redirecting stdout inside a loop

hi, OK. I am writing a bash script, and it is almost working for me. Problem 1: I currently have stout sent to a file (stout.miRNA.bash.$date_formatted) which I would like to have work inside my loop, but when I move it, it just prints to the screen. Problem 2: I have a second file... (18 Replies)
Discussion started by: hmortens
18 Replies

2. Shell Programming and Scripting

Redirecting stdout continously to a file

I have a C program that continously outputs info to stdout. The problem is that I am redirecting the stdout and stderr to a file and stdout is written at the end of the problem rather than continously to the file. This could be a problem if for example the program is killed and the stdout output is... (3 Replies)
Discussion started by: igurov
3 Replies

3. Shell Programming and Scripting

Redirecting stdout problem

I have a simple bash script that prints sth every 5 seconds. What I do is the following. I redirect the output of the script to a file, tail the file and see that it works and then from another console I delete the file where the output is redirected to. Even though I have deleted the file, the... (2 Replies)
Discussion started by: igurov
2 Replies

4. Shell Programming and Scripting

Redirecting stdout to variable while printing it

Hi everybody, I am trying to do the thing you see in the title, and I can't simply do a=$(svn up) echo $a because the program (svn) gives output on lots of lines and in the variable the output is stored on only one line (resulting in a horribly formatted text). Any tips? Thanks,... (2 Replies)
Discussion started by: ocirne94
2 Replies

5. Shell Programming and Scripting

redirecting to stdout in betwen command

can anyone help me in making singleline command for Capital Letters are folders ,small letter are files X,Y,Z are subfolders of A as shown below A - X,Y,Z Folder X has three files a.txt,b.txt,c.txt similarly Y,Z. as shown below X- a.txt,b.txt,c.txt Y- a.txt,b.txt,c.txt Z-... (4 Replies)
Discussion started by: phoenix_nebula
4 Replies

6. Shell Programming and Scripting

Redirecting stdin/stdout to/from command from/to string

Hi, I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results: system("nasm -f elf program.asm >... (5 Replies)
Discussion started by: doc_cypher
5 Replies

7. UNIX for Dummies Questions & Answers

Redirecting several outputs to /dev/stdout

I have an executable that, depending on its input, outputs to either one file or several. It usually prints nothing on screen. The usual way to call this program is to specify an input and output filenames, like this: ./executable.exe -i inputfile -o outputfileIt will then try to use the output... (1 Reply)
Discussion started by: aplaydoc
1 Replies

8. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies

9. Shell Programming and Scripting

implicitly redirecting stdout to a file

Is there a way to redirect all stdout to a file implicitly - like defining stdout=/home/me/process.log - so that all "echo" commands in several scripts/subscripts are written to that file; instead of having to edit all scripts to redirect the "echo" (e.g. echo 'This is a test ' >>... (1 Reply)
Discussion started by: ALTRUNVRSOFLN
1 Replies

10. Shell Programming and Scripting

redirecting STDOUT & STDERR

In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas? (9 Replies)
Discussion started by: jshinaman
9 Replies

Featured Tech Videos