Can I do it using python?? about xterm and telnet

V

valpa

I'm a net admin for about 20 unix servers, and I need to frequently
telnet on to them and configure them.
It is a tiring job to open a xterm and telnet, username, password to
each server.

Can I do it automatically by python? After that, there have 20 xterm
consoles opened and telneted to their corresponding servers. Then I
could start to type command in these xterms.

Any suggestion appreciate. Much thanks.
 
J

Jim Segrave

I'm a net admin for about 20 unix servers, and I need to frequently
telnet on to them and configure them.
It is a tiring job to open a xterm and telnet, username, password to
each server.

Don't use telnet. it's clumsy and has security issues.

Use ssh with RSA or DSA keys. Then you simply do:

ssh username@machine_name

in an xterm and you are loggedis as user username on server
machinename. It's vastly more secure and more reliable.

If you're talking about initial setup of a machine (OS installation or
whatever), our solution was to have a post-install CD or floppy which
fetched standard server configuration data. This included an ssh
public key for our ssh-key distribution, so after running the
post-install disc, we could push out staff ssh-keys and logins were
available.
 
P

placid

Jim said:
Don't use telnet. it's clumsy and has security issues.

if youre behind a firewall then it shouldnt matter.
Use ssh with RSA or DSA keys. Then you simply do:

ssh username@machine_name

in an xterm and you are loggedis as user username on server
machinename. It's vastly more secure and more reliable.

If you're talking about initial setup of a machine (OS installation or
whatever), our solution was to have a post-install CD or floppy which
fetched standard server configuration data. This included an ssh
public key for our ssh-key distribution, so after running the
post-install disc, we could push out staff ssh-keys and logins were
available.

I dont think the OP wants to do post-install configuration (i may be
wrong! ) but to change for example some config file.

You should be able to create a dictionary containing username=password,
then iterate over this dictionary and use os.system("xterm -e telnet -u
%s -p %s") where -u is username and -p is password (im not quite sure
if telnet has these arguments or if it works like this too)

Cheers
 
V

vasudevram

Just FYI - pexpect is a Python app that works like Expect - which is by
Don Libes and written in TCL. Expect comes with most Linux
distributions and is available for most UNIX / Linux versions from its
web site http://expect.nist.gov/

The expect man page is enough to get started for simple needs, such as
yours appears to be. You might want to play around with the original
Expect a bit and then try out pexpect - or you could just use Expect
itself for your needs.

HTH
Vasudev
---
Vasudev Ram
Independent software consultant
http://www.geocities.com/vasudevram
PDF conversion toolkit:
http://sourceforge.net/projects/xtopdf
---
 
N

Network Ninja

valpa said:
I'm a net admin for about 20 unix servers, and I need to frequently
telnet on to them and configure them.
It is a tiring job to open a xterm and telnet, username, password to
each server.

Can I do it automatically by python? After that, there have 20 xterm
consoles opened and telneted to their corresponding servers. Then I
could start to type command in these xterms.


I often have to add users/delete local user accounts on routers and
switches. Each account is a local account, and I got tired of it. My
very first python program was created to use the telnetlib, and either
add, delete, or show a list of user accounts. It was very effective,
because it would change the same accounts on each router and switch.
Saved me a bunch of time, and got me hooked on python. If you are not
concerned about security, the telnetlib in python will help you.
Otherwise, use ssh, as it is more secure. You can even impliment
public/private keys for password-less log on. If you want some help
with the code for the telnetlib, let me know.
 
C

cmdrrickhunter

I used this _EXACT_ solution(copied below) at work a month ago, to
start 20ish programs, each with different settings. In this case I HAD
to use telnet for some of them, because they were on an embedded
machine, 4 of them used SSH(across the internet), and the rest were
local programs. It worked flawlessly each time (every restart of the
network... which was quite often in this case). There may be more
integrated solutions which solve the problem, but expect is rediculousy
easy to use, and is very deterministic as long as the commands work.
If the commands fail to work (such as someone deletes your program),
debugging is rather difficult, but at least you have a full dump of
everything sent by the server (because pexpect prints it all to the
screen). Also, once the connection is open, you can call
conn.interact() and it will make the terminal interactive, just like
any other shell.
 
L

Lawrence D'Oliveiro

"valpa said:
I'm a net admin for about 20 unix servers, and I need to frequently
telnet on to them and configure them.
It is a tiring job to open a xterm and telnet, username, password to
each server.

Do you need to replicate identical configurations to all the servers?

If so, perhaps you're approaching this the wrong way. A better solution
might be to look at replicating the config files directly to all
machines (using rsync, scp etc), rather than editing them in situ on
every single one.
 
C

cmdrrickhunter

agreed, SSH is advisable over telnet in nearly all situations.
However, there are a few times where telnet is better.
1. Embeded machines often have stripped down OS's. Telnet is much
smaller and cheaper than a full blown SSH install. When every byte
counts, you wont find SSH
2. He may have a pre-existing network which his job does not allow him
to modify.

In either case, pexpect will do the job you need. Build the scripts
with pexpect, and then look into whether or not you can upgrade from
telnet to SSH. Converting a pexpect script from telnet to SSH is
trivial.

I've got a few scripts to do exactly what you are asking to do, from a
Gnome machine, along with an XML file to configure it. It spawns a
gnome multi-terminal with all the tabs, then telnets, ssh's, or
connects to the local machine, and runs a command. Once that command
is done, the window enters "interactive" mode and behaves just like any
other shell.

Are you at liberty to explain the network more fully? Mr. D'Oliveiro
makes an excelent point. When you're doing the same thing to a bunch
of machines, there's a good chance that a unix sysadmin has banged
his/her head on the table over the same problem, and wrote a program to
do this. Programs like rsync exist because of the challenges of
keeping multiple machine synchronized.

Annother option would be to do some creative mounting of NFS volumes.
A unix guru would be able to direct you to the most elegant solution
 
N

Nicko

placid said:
if youre behind a firewall then it shouldnt matter.

No, no, no! If you have 20 unix servers then this is likely not a tiny
company. Most security breaches (according to the FBI/CSI computer
crime survey) are perpetrated by insiders. If you log in using telnet,
and have to enter passwords that allow configurations to be changed,
then anyone on the local net can get those passwords. Use SSH instead.
Even SSH with passwords is hugely more secure than telnet.

Nicko
 
V

valpa

Thanks,

But I need to to do complicated job in the xterm consoles for servers.
So I need
to open many xterm consoles and I just want to save my time from
telneting...usr/pwd...
 
C

cmdrrickhunter

I can get to my code on wednesday, I'll upload it somewhere you can get
a copy of it. But do look into using SSH, because in the long run it
is a far better tool. A properly configured SSHD also opens the way to
scp. Without scp, copying files means ftp, or unsecured rsync.

Do you want tabbed windows, or just a distinct xterm for each?
 
V

valpa

I don't care about security issue by now :), because every one in my
compony know the username/password. It's a shared password. I just want
to login into Unix boxes in an efficiently. so I needn't open a xterm
console and type telent ..... usr/pwd for a unix box, and open another
xterm, type telnet ...usr/pwd, and so on...
 
P

Paul Rubin

valpa said:
Can I do it automatically by python? After that, there have 20 xterm
consoles opened and telneted to their corresponding servers. Then I
could start to type command in these xterms.

Have python launch "xterm -e somecommand" for each server. somecommand
would then be another python script (or whatever) that opens a telnet
connection to that server. See the xterm docs for more info.

Maybe what you really want is to remotely execute reconfiguration
commands, instead of opening all those xterms to use manually. See
rsh, ssh, etc.
 
L

Lawrence D'Oliveiro

"valpa said:
I don't care about security issue by now :), because every one in my
compony know the username/password.

Then why bother with a password at all?
 
?

=?windows-1250?Q?Petr_Jake=9A?=

v> Thanks,

v> But I need to to do complicated job in the xterm consoles for servers.
what does it mean, complicated job? Can you be more specific, please?
v> So I need
v> to open many xterm consoles and I just want to save my time from
v> telneting...usr/pwd...

 
V

valpa

Maybe I'm not state what I want clearly.

These Unix boxes are not doing important job like email, web server,
etc.
In our lab, these unix boxes are connected to be a network system to
run our protocols and our job is to test the protocols. they are
physically seperated from lab network and seperate from Internet. So I
do not consider the security issue.

There will be a lot of work to do after I login into these servers. I'm
tired to typing the command "telnet".. and I want to do "telnet"
automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top