Re: Bash script - telnet
From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 05/27/04
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Bash script - telnet"
- In reply to: Tokito: "Bash script - telnet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Bash script - telnet"
- In reply to: Tokito: "Bash script - telnet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|