Operating System - Linux
1820590 Members
2036 Online
109626 Solutions
New Discussion юеВ

Automatic telnet ( non-interactive telnet) within Unix servers

 
anil_garg5
Occasional Contributor

Automatic telnet ( non-interactive telnet) within Unix servers

HI Group,
I have an urgent requirement to automatic telnet few Linux and Unix servers through some script and then run a health status check script.

I have tried a Perl based script.
============================================
#!/usr/bin/perl -w
# perl telnet1.pl username password hostname
use Net::Telnet;
# Get number of command-line arguments.
$num_args = scalar( @ARGV );
if ( $num_args < 2) {
die "Usage: username password hostname\n";
}
$username = shift;
$password = shift;
$hostname = shift;
$tel = Net::Telnet->new(Host => $hostname,
Input_log => тАШtelnet.txtтАЩ,
Timeout => 30 );
$tel->login($username, $password)
or die "Unable to establish telnet connection $!";
# Issue a command on the remote system.
@df_result = $tel->cmd("df");

foreach $line (@df_result) {
print "$line";
}
$tel->close();
# telnet1.pl
===============================================
$perl telnet1.pl username password hostname
this script is working on non-interactive telnet with localhost but did not connecting with remote hosts.
Please guide what I need to modify here or if someone is using any script for such situation,PLEASE PLEASE send me.

Thanks a lot ..........
Anil
anil_garg5@yahoo.com
10 REPLIES 10
Ivan Ferreira
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

I think that will be better and maybe more secure to setup a ssh connection with public keys and no passphrase. You can use the PermitRootLogin forced-commands-only option. And then you can use ssh to get the status of the remote server.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
anil_garg5
Occasional Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

Thanks for your reply....
Only the telnet service is configured in all the remote servers. ssh service is disaled in all the server, so I have no choice..How can tackle this in present situation? Please guide.
Sergejs Svitnevs
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

It is also usefull to check that:

1) telnetd is installed and running on your remote Linux&Unix machines.

2) Your mgmt host is allowed to connect to all remote hosts (add "in.telnetd:" to the bottom of the /etc/hosts.allow file on all hosts).

Regards,
Sergejs
Ivan Ferreira
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

What is the error that you get, can you interactively telnet to the remote host?
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Bill Thorsteinson
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

I would seriously consider installing sshd
where it is missing.

If you want to do health checks then
seriously consider installing nagios
or one of the programs of its ilk.

Both options are much more secure.

Also if you are connecting as root, this
may be prevented (quite rightly) by
/etc/securetty, or a similar file.
anil_garg5
Occasional Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

Thanks a lot all.
I have installaed sshd on Linux machine.
but unable to install sshd on the Solaris machine.I am still working on it.

Thanks,
Muthukumar_5
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

For automation you can try with,

a) expect
b) telent + piping() as,

(
echo "root"
sleep 2
echo ""
sleep 2
echo "command to execute"
sleep 2
echo "exit"
) | telnet machine

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

Problem is,

sometime telnet service is not enabled in all machines of *NIX. It depends upon your machines. Try to check all the machines for common login service availablity. Then automate with perl or expect scripting or telnet + piping.

--
Muthu
Easy to suggest when don't know about the problem!
Alan_152
Honored Contributor

Re: Automatic telnet ( non-interactive telnet) within Unix servers

You might want to look into using EXPECT, withg either telnet or ssh.
Stephen Barratt
New Member

Re: Automatic telnet ( non-interactive telnet) within Unix servers

One alternative to public keys and no passphrase is to use keychain. On login, you're asked for your passphrase once, then keychain handles authentication after that. You don't need to input your passphrase again unless you reboot.