By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,496 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Jul 2 '06 #1
Share this Question
Share on Google+
20 Replies


P: n/a
In article <11*********************@b68g2000cwa.googlegroups. com>,
valpa <va********@gmail.comwrote:
>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.


--
Jim Segrave (je*@jes-2.demon.nl)

Jul 2 '06 #2

P: n/a

Jim Segrave wrote:
In article <11*********************@b68g2000cwa.googlegroups. com>,
valpa <va********@gmail.comwrote:
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.
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

Jul 2 '06 #3

P: n/a
try pexpect.
http://pexpect.sourceforge.net/

valpa wrote:
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.
Jul 2 '06 #4

P: n/a
try pexpect.
http://pexpect.sourceforge.net/

valpa wrote:
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.
Jul 2 '06 #5

P: n/a

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
---
faulkner wrote:
try pexpect.
http://pexpect.sourceforge.net/

valpa wrote:
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.
Jul 2 '06 #6

P: n/a

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

Jul 2 '06 #7

P: n/a
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.
vasudevram wrote:
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
---
faulkner wrote:
try pexpect.
http://pexpect.sourceforge.net/

valpa wrote:
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.
Jul 2 '06 #8

P: n/a
In article <11*********************@b68g2000cwa.googlegroups. com>,
"valpa" <va********@gmail.comwrote:
>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.
Jul 3 '06 #9

P: n/a
In article <11**********************@j8g2000cwa.googlegroups. com>,
"placid" <Bu****@gmail.comwrote:
>Jim Segrave wrote:
>Don't use telnet. it's clumsy and has security issues.

if youre behind a firewall then it shouldnt matter.
Still not a good idea.
Jul 3 '06 #10

P: n/a
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

Jul 3 '06 #11

P: n/a
placid wrote:
Jim Segrave wrote:
In article <11*********************@b68g2000cwa.googlegroups. com>,
valpa <va********@gmail.comwrote:
>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.

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

Jul 3 '06 #12

P: n/a
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...

Network Ninja wrote:
valpa wrote:
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.
Jul 3 '06 #13

P: n/a
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?
valpa wrote:
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...
Jul 3 '06 #14

P: n/a
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...
Nicko wrote:
placid wrote:
Jim Segrave wrote:
In article <11*********************@b68g2000cwa.googlegroups. com>,
valpa <va********@gmail.comwrote:
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.
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
Jul 3 '06 #15

P: n/a
"valpa" <va********@gmail.comwrites:
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.
Jul 3 '06 #16

P: n/a
In article <11**********************@m79g2000cwm.googlegroups .com>,
"valpa" <va********@gmail.comwrote:
>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?
--
A: Skid-marks in front of the hedgehog.
Q: What's the difference between a dead hedgehog on the road, and a dead
top-poster on the road?
Jul 3 '06 #17

P: n/a
vThanks,

vBut 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?
vSo I need
vto open many xterm consoles and I just want to save my time from
vtelneting...usr/pwd...

vNetwork Ninja wrote:
>valpa wrote:
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

Jul 3 '06 #18

P: n/a
telnet server must have a password, right?

Lawrence D'Oliveiro wrote:
In article <11**********************@m79g2000cwm.googlegroups .com>,
"valpa" <va********@gmail.comwrote:
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?
--
A: Skid-marks in front of the hedgehog.
Q: What's the difference between a dead hedgehog on the road, and a dead
top-poster on the road?
Jul 3 '06 #19

P: n/a
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.

Lawrence D'Oliveiro wrote:
In article <11**********************@m79g2000cwm.googlegroups .com>,
"valpa" <va********@gmail.comwrote:
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?
--
A: Skid-marks in front of the hedgehog.
Q: What's the difference between a dead hedgehog on the road, and a dead
top-poster on the road?
Jul 3 '06 #20

P: n/a
valpa schrieb:
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.
Is there a framework/module to automate ssh-sessions/scp-filetransfers
with python-programming ?

Best regards

Marc schoechlin
Jul 4 '06 #21

This discussion thread is closed

Replies have been disabled for this discussion.