0

I'm trying to write a shell script to send an AT command to serial port and store it's response to a file.

I'm able to send the AT command as shown below, but not sure how to save the output from the ttyUSB1 to a file.

echo -e "AT+CSQ\r" > /dev/ttyUSB1

Is there a way to do it using shell script apart from atinout? I cannot use atinout because the atinout command to save the AT response to a file doesn't work for me.

2
  • Maybe the expect utility for automating interactive programs is a solution. It can send and expect strings matching regular expressions. Commented Dec 8, 2021 at 11:37
  • @Jens: I'm not sure about this and i don't have the said package on my board. Commented Dec 8, 2021 at 12:16

1 Answer 1

0

You can emulate CTRL+C on a shell command. If you execute your commands in backgroud inside your shell script, you can kill the last command with the following sequence, provided that your command lasts less than 20 seconds:

pid=$!
sleep 20
kill ${pid}
Sign up to request clarification or add additional context in comments.

4 Comments

This is quite brittle. Using a dedicated utility which understands the conventions of the communications protocol - if you can find one - is usually a superior approach.
@Saxon: The source code of atinout is written such that the output of an AT command gets saved to a file, which doesn't work for me. and i think the reason is because my serial port does not return the control back until i press ctrl+c. But even with that, there's no output in my file. So, i was just stating why i cannot use atinout and i'm trying to work around using shell script, if possible.
@tripleee: I don't know why you have marked it as duplicate, but my question is totally different. I want to save the AT command response to a file using shell script and the answer that you have linked to doesn't even talk anything regarding that. I have edited my question and highlighted few things. Hope that helps.
The extension to save the output to a file rather than display it on your terminal seems like a simple and obvious tweak. I'll check if I can find a duplicate which covers that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.