Find the answer to your Linux question:
Results 1 to 2 of 2
hi,i program my telnet on bash script but it fail.it appear like this: DES-3326SR Fast Ethernet Switch Command Line Interface Firmware: Build 4.03-B01 Copyright(C) 2000-2005 D-Link Corporation. All rights reserved. ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    1

    telnet

    hi,i program my telnet on bash script but it fail.it appear like this:

    DES-3326SR Fast Ethernet Switch Command Line Interface

    Firmware: Build 4.03-B01
    Copyright(C) 2000-2005 D-Link Corporation. All rights reserved.
    UserName:fazly
    Connection closed by foreign host.

    this my coding:

    Code:
    host=10.90.90.90
    port=23
    export UserName=fazly
    export PassWord=cat
    
    timeout=3
    file=file1
    prompt="$"
    (echo open ${host} ${port}
    sleep 1
    tout=${timeout}
    while [ "${tout}" -ge 0 ]
    do
        if tail -1 "${file}" 2>/dev/null | egrep -e "UserName:" > /dev/null
        then
            echo "${UserName}"
            sleep 1
            tout=-5
            continue
        else
            sleep 1
     tout=`expr ${tout} - 1`
        fi
    done
    
    if [ "${tout}" -ne -5 ]; then
      exit 1
    fi
    
    tout=${timeout}
    while [ "${tout}" -ge 0 ]
    do
        if tail -1 "${file}" 2>/dev/null | egrep -e "PassWord:" > /dev/null
        then
            echo "${PassWord}"
            sleep 1
            tout=-5
            continue
        else
          if tail -1 "${file}" 2>/dev/null | egrep -e "${prompt}" > /dev/null
          then
            tout=-5
          else
            sleep 1
      tout=`expr ${tout} - 1`
          fi
        fi
    done
    
    if [ "${tout}" -ne -5 ]; then
      exit 1
    fi
    
    > ${file}
    sleep 1
    echo logout) | telnet
    exit $?
    i need help..........
    
    so i try another one but still fail.
    
    DES-3326SR Fast Ethernet Switch Command Line Interface
    
                                Firmware: Build 4.03-B01
              Copyright(C) 2000-2005 D-Link Corporation. All rights reserved.
    UserName:fazly
    PassWord:*******
    Fail!
    Connection closed by foreign host.
      my coding like this:
    
    #host=10.90.90.90
    #port=23
    UserName=fazly
    PassWord=ca
    (echo open ${host} ${port}
    sleep 1
    echo ${UserName}
    sleep 1
    echo ${PassWord}
    sleep 1
    echo exit) | telnet
    Last edited by bigtomrodney; 06-05-2007 at 02:25 PM. Reason: Added code tags

  2. #2
    Just Joined! Sivel's Avatar
    Join Date
    Jun 2005
    Location
    Maryland
    Posts
    20
    Don't you think it would be easier to use Perl with the Net::Telnet module?

    Or if you don't want to use perl you could use expect/tcl. Shell scripting just isn't the right choice for what you are trying to accomplish.

    Net::Telnet:
    Net::Telnet - interact with TELNET port or other TCP ports - search.cpan.org


    Expect:
    Tcl/Tk - What is Expect? Why use it?
    Using Expect

Posting Permissions

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