Re: Bash script - telnet

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 05/27/04

  • Next message: Bill Marcum: "Re: file and magic"
    Date: Thu, 27 May 2004 01:54:51 GMT
    
    

    On 26 May 2004 16:03:37 -0700, Tokito <maramire@tutopia.com> wrote:
    >
    >
    > Hi masters!
    > I need a telnet script in bash. I need to log in a remote site for
    > executing certain commands & tasks (remotely). Can somebody share a
    > script like this? I use Debian Woody.
    >
    >

    Greetings, Tokito-san

    Like Jens said, expect is a good tool for this. If you want to use bash,
    it much easier to use nc (netcat) than it is telnet.

    See the FAQ that comes with the package. Here's a script that logs into
    a POP server and retrieves the headers from all the mail there:

    #! /bin/bash

    (echo user your_username
    echo pass your_password
    echo stat
    while true
    do
    sleep 1
    if [ -s mailfile ]
    then
    num=`tail -1 mailfile | sed -n 's/\(+OK \)\([0-9][0-9]*\)\
    \( [^ ][^ ]*\)/\2/p'`
    break
    else continue
    fi
    done
    echo list
    sleep 1
    j=1
    until [ $j -gt $num ]
    do
    echo -n $j >> numfile
    echo -n " " >> numfile
    j=`expr $j + 1`
    done
    sleep 1
    for i in `cat numfile`
    do
    echo top $i 0
    done
    echo quit)| netcat -vvv pop.whatever.net 110 > mailfile

    Notice that "echo" preceeds the commands to the remote server.

    For a script to do what you want, you'd have to supply a lot of
    details.

    The first step in writing any program/script is to write it out in
    plain English:

    1. connect to server

    2. login to server

    3. do this on server

    4. do this here

    ...

    N. log off server and quit program

    You can also use pure bash. From man bash:

    /dev/tcp/host/port
                         If host is a valid hostname or Internet
                         address, and port is an integer port number
                         or service name, bash attempts to open a TCP
                         connection to the corresponding socket.

    I just like nc, and it's only 17K. More portable, for one thing...

    AC

    -- 
    Pass-List -----> Block-List ----> Challenge-Response
    The key to taking control of your mailbox.  Design Parameters:
    http://tinyurl.com/2t5kp ||   http://tinyurl.com/3c3ag
    Challenge-Response links -- http://tinyurl.com/yrfjb
    

  • Next message: Bill Marcum: "Re: file and magic"

    Relevant Pages

    • My solution for preventing xhost +
      ... from running xhost + and thereby exposing an/the X server. ... If the script detects this condition, ... echo "Re-enabling access control per Security Policy." ...
      (Focus-SUN)
    • Re: Why cant ISPs stop spam/virus ?!
      ... (elrav1 would handle this situation better: ... and pass on the script that talks to the POP server. ... (echo user joeblow@whatever.net ...
      (comp.os.linux.misc)
    • Re: Why cant ISPs stop spam/virus ?!
      ... (elrav1 would handle this situation better: ... and pass on the script that talks to the POP server. ... (echo user joeblow@whatever.net ...
      (comp.os.linux.misc)
    • Re: Admin Password
      ... here is a script from ... @ECHO OFF ... Put one server per line. ... :: Set the location of the Local tool. ...
      (microsoft.public.windows.server.scripting)
    • Re: Bash 2.05 and SCO OpenServer 5.0.6
      ... I have not seen a script that didn't work in ksh with only the ... >> running bash at the time this unforseen script got called. ... # repeat 3 echo hi ...
      (comp.unix.sco.misc)

  • Quantcast