Alex Alex - 1 year ago 172
Linux Question

How to send a sequence of AT commands to a serial port in bash?

In Linux I need to send a sequence of AT commands to a serial port on e.g.

, which has to wait for an
answer before the next command is sent. I could imagine doing something like

echo 'AT' > /dev/ttyS0
echo 'ATS0=0' > dev/ttyS0

but this does not evaluate the answer from the device on that port.

Is there a very simple way to automate this within a bash script, probably with the help of
but no tools which cannot found on the most simple linux system.

Answer Source

If you install the PPP package you can use the chat program that comes with it. Or you can use kermit. Or the cu program that comes with uucp. But to do it with pure shell is trickier. You might be able to use the read and printf functions, with stdio redirected to the port.

some snippet:

stty -F /dev/ttyS0 38400 raw
chat -f script.txt < /dev/ttyS0 > /dev/ttyS0

Should get you started.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download