Results 1 to 15 of 15

Thread: Linux: automatic modem configuration

  1. #1
    Registered User El Salsero Gringo's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,881
    Rep Power
    12

    Linux: automatic modem configuration

    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!

  2. #2
    The Gobby one! WittyBird's Avatar
    Join Date
    Aug 2005
    Location
    Geekville
    Posts
    6,889
    Rep Power
    13

    Re: Linux: automatic modem configuration

    Think your problem is the fact that its tiny but will ask the other guru's tomorrows

  3. #3
    Lovely Moderator ducasi's Avatar
    Join Date
    Feb 2005
    Location
    Glasgow
    Posts
    10,015
    Rep Power
    14

    Re: Linux: automatic modem configuration

    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...

    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
    Some tweaking, maybe a "stty" or two, but that is all that you really need...

    Hope this helps...
    Let your mind go and your body will follow. – Steve Martin, LA Story

  4. #4
    Registered User El Salsero Gringo's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,881
    Rep Power
    12

    Re: Linux: automatic modem configuration

    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!

  5. #5
    Lovely Moderator ducasi's Avatar
    Join Date
    Feb 2005
    Location
    Glasgow
    Posts
    10,015
    Rep Power
    14

    Re: Linux: automatic modem configuration

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

    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...

    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
    Theoretically, uncommenting one of those "Tx" lines should do the right thing... Consult the man pages for inittab and getty for more details.

    Good luck!
    Let your mind go and your body will follow. – Steve Martin, LA Story

  6. #6
    Registered User tomboh's Avatar
    Join Date
    Dec 2005
    Location
    Milton Keynes
    Posts
    39
    Rep Power
    10

    Re: Linux: automatic modem configuration

    Quote Originally Posted by El Salsero Gringo
    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?
    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.

    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?

  7. #7
    Registered User
    Join Date
    Mar 2003
    Location
    bedford
    Posts
    4,899
    Rep Power
    13

    Re: Linux: automatic modem configuration

    Quote Originally Posted by tomboh
    ...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.

  8. #8
    Registered User tomboh's Avatar
    Join Date
    Dec 2005
    Location
    Milton Keynes
    Posts
    39
    Rep Power
    10

    Re: Linux: automatic modem configuration

    Quote Originally Posted by bigdjiver
    This geeky stuff is invaluable to some of us, and is one reason why we have the neg rep facility.
    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.

    Would it help if I told you a bigger, older boy told bullied me into writing that?

  9. #9
    Lovely Moderator ducasi's Avatar
    Join Date
    Feb 2005
    Location
    Glasgow
    Posts
    10,015
    Rep Power
    14

    Re: Linux: automatic modem configuration

    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

  10. #10
    Registered User
    Join Date
    Mar 2003
    Location
    bedford
    Posts
    4,899
    Rep Power
    13

    Re: Linux: automatic modem configuration

    Quote Originally Posted by tomboh
    ... Would it help if I told you a bigger, older boy told bullied me into writing that?
    No, I had assumed it was a bigger older girl.

    (Actually I have passed the thread onto a geeky friend having a related problem )

  11. #11
    Registered User El Salsero Gringo's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,881
    Rep Power
    12

    Re: Linux: automatic modem configuration

    Quote Originally Posted by tomboh
    Do you mean a telnet session as opposed to a TCP port?
    Quite right - I was being sloppy. I meant a TCP port.


    Many thanks, everyone - much for me to work on here.

    Quote Originally Posted by tomboh
    Wait: didn't I sign up to a dance forum thing to escape from computers?
    There is *no* escape.

  12. #12
    Registered User
    Join Date
    Mar 2003
    Location
    bedford
    Posts
    4,899
    Rep Power
    13

    Re: Linux: automatic modem configuration

    Quote Originally Posted by bigdjiver
    No, I had assumed it was a bigger older girl.
    Ah, the joys of windows. Now it is possible to mess up 4 things more or less simultaneously

  13. #13
    Registered User
    Join Date
    Jul 2004
    Location
    London
    Posts
    1,227
    Rep Power
    10

    Re: Linux: automatic modem configuration

    Quote Originally Posted by El Salsero Gringo
    There is *no* escape.
    How about '/'?

  14. #14
    Lovely Moderator ducasi's Avatar
    Join Date
    Feb 2005
    Location
    Glasgow
    Posts
    10,015
    Rep Power
    14

    Re: Linux: automatic modem configuration

    Quote Originally Posted by Andreas
    How about '/'?
    This is Linux we're talking about here, so I think you mean "\" (or even just "^[".)
    Let your mind go and your body will follow. – Steve Martin, LA Story

  15. #15
    Registered User
    Join Date
    Jul 2004
    Location
    London
    Posts
    1,227
    Rep Power
    10

    Re: Linux: automatic modem configuration

    Quote Originally Posted by ducasi
    This is Linux we're talking about here, so I think you mean "\" (or even just "^[".)
    Got me there.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linux DVD to avi converter
    By Clive Long in forum Geeks' Corner
    Replies: 2
    Last Post: 24th-September-2006, 09:46 PM
  2. Where can I get a modem?
    By Ste in forum Geeks' Corner
    Replies: 6
    Last Post: 18th-August-2006, 10:46 AM
  3. Automatic Thread Subscription?
    By Rhythm King in forum Forum technical problems / Questions / Suggestions..
    Replies: 3
    Last Post: 22nd-January-2006, 12:01 AM
  4. Automatic Gender Balancing
    By Jeremy in forum Let's talk about dance
    Replies: 52
    Last Post: 10th-January-2006, 05:25 PM
  5. Win XP functionality / configuration
    By Bob in forum Geeks' Corner
    Replies: 7
    Last Post: 9th-January-2006, 12:19 AM

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •