Think your problem is the fact that its tiny but will ask the other guru's tomorrows
Here's a question for the Linux experts:
I have a tiny PC running Debian Linux as an unattended 'box'.
it's attached to a network segment which also has a satellite transceiver; iEach host on the network that wishes to send data over the satellite link needs to telnet to the satellite unit and send a sequence of three AT commands before it can send any IP packets via the satellite.
Normally these AT commands are sent by a piece of configuration software (a kind of control panel) that would run on each PC wishing to access the WAN.
What I need to do is to create a script for the linux unit that will run automatically at startup to send the correct command sequence. By choice I'd probably use Expect because that's what it's designed for; but this Debian system is a minimalist install and probably doesn't have Expect. What else can I use, how would I write the script, and how would I make it run at startup?
One complication is that the AT commands can take up to 60 or more seconds to return - usually with "OK" but possibly with an error. If an error is returned then I need the system to wait say 60 seconds then restart the script. The system has no screen, no keyboard and no possibility of user intervention, so I'm happy for it to keep trying the command sequence until it eventually succeeds.
Clearly I'm not a Linux expert, so feel free to make as many obvious points as you wish - I'm bound to learn something.
Thanks!
Think your problem is the fact that its tiny but will ask the other guru's tomorrows
Off the top of my head... a wee shell script in /etc/rc1.d/ or similar... Call it "S99.modem-config". (The "99" might need to be smaller to get this to run before the rest of the network stuff...)
(The proper way of doing this is to put the script in /etc/init.d/ and run update-rc.d, but I'm going to ignore that...)
Here's a quick hacked-up script...
Some tweaking, maybe a "stty" or two, but that is all that you really need...Code:#! /bin/sh - # what we're talking to... MODEM=/dev/ttya exec >$MODEM <$MODEM function echook() { echo "$@" sleep 2 read a test "$a" == "OK" } while true do sleep 60 echook "AT1111" || continue sleep 10 echook "AT2222" || continue sleep 10 echook "AT3333" || continue break done
Hope this helps...
Let your mind go and your body will follow. – Steve Martin, LA Story
Hi Ducasi,
That's brilliant. The commands actually have to be passed over a telnet session to a particular address and port (192.168.128.100 port 1829, say) - how do I use a network socket rather than ttya?
Also (not really related) question: how do I configure the unit to run a terminal session on serial port 1 so I can use a laptop with say, Hyperterminal to log in to the unit?
Thanks!
OK, assuming that the shell you are using is bash (echo $BASH_VERSION will tell you if it is), and things work as advertised, then here's a revised script:
I've never used bash's "/dev/tcp" built-in networking, so I'm not 100% sure that it'll work... Because I'm now using bash-specific features, I've changed the script to specify bash explicitly.Code:#! /bin/bash - # time-out on reads... TMOUT=60 # what we're talking to... HOST=host.name.or.ip.no PORT=port# MODEM=/dev/tcp/$HOST/$PORT function echook() { echo "$@" sleep 2 read a test "$a" == "OK" } while true do exec <>$MODEM >&0 && break sleep 10 done delay=1 while true do sleep $delay delay=60 echook "AT1111" || continue sleep 10 echook "AT2222" || continue sleep 10 echook "AT3333" || continue break done
To spawn a login prompt on one of the serial ports, edit /etc/inittab and see what is says... A Debian machine I'm using has this...
Theoretically, uncommenting one of those "Tx" lines should do the right thing... Consult the man pages for inittab and getty for more details.Code:# /sbin/getty invocations for the runlevels. # # The "id" field MUST be the same as the last # characters of the device (after "tty"). # # Format: # <id>:<runlevels>:<action>:<process> # # Note that on most Debian systems tty7 is used by the X Window System, # so if you want to add more getty's go ahead but skip tty7 if you run X. # 1:2345:respawn:/sbin/getty 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 3:23:respawn:/sbin/getty 38400 tty3 4:23:respawn:/sbin/getty 38400 tty4 5:23:respawn:/sbin/getty 38400 tty5 6:23:respawn:/sbin/getty 38400 tty6 # Example how to put a getty on a serial line (for a terminal) # #T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100 #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100 # Example how to put a getty on a modem line. # #T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
Good luck!
Let your mind go and your body will follow. – Steve Martin, LA Story
Do you mean a telnet session as opposed to a TCP port? The telnet protocol uses funky characters to auto-negotiate stuff (yeah, I'm not quite sure what) and while you may need to do this, if you're thinking along the lines of "connect to port 80 for HTTP', use netcat(1). On Debian you'll need to do an "apt-get install netcat" if it's not already installed.Originally Posted by El Salsero Gringo
netcat is a wonderful tool: it essentially allows you to redirect stuff between arbitrary machines instead of pipelines on the same host.
Wait: didn't I sign up to a dance forum thing to escape from computers?
This geeky stuff is invaluable to some of us, and is one reason why we have the neg rep facility.Originally Posted by tomboh
Really, talking about computers might make me unpopular? I never knew! I kept wearning the pointy hat and standing in the corner because I thought it would make everyone love me.Originally Posted by bigdjiver
Would it help if I told you a bigger, older boy told bullied me into writing that?
I would have suggested using netcat, but bash seems to have enough TCP goodness built-in that it's not needed in this instance.
Let your mind go and your body will follow. – Steve Martin, LA Story
No, I had assumed it was a bigger older girl.Originally Posted by tomboh
(Actually I have passed the thread onto a geeky friend having a related problem )
Quite right - I was being sloppy. I meant a TCP port.Originally Posted by tomboh
Many thanks, everyone - much for me to work on here.
There is *no* escape.Originally Posted by tomboh
Ah, the joys of windows. Now it is possible to mess up 4 things more or less simultaneouslyOriginally Posted by bigdjiver
How about '/'?Originally Posted by El Salsero Gringo
This is Linux we're talking about here, so I think you mean "\" (or even just "^[".)Originally Posted by Andreas
Let your mind go and your body will follow. – Steve Martin, LA Story
Got me there.Originally Posted by ducasi
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks