Hello I am working on a perl prg to change passwd on several servers at one time. I am new to perl and this is my first program, been trying to get to work this one out. Can some one tell me what is worng or actually help me out?)
This one ask the user for the remote login, remote old_passwd and the new_passwd and change it in all the unix boxes. When ever I try to run it gives me an error saying time out (at the cmd(passwd))line. Anyways here is the code:
use strict;
use IO::File;
use DBI;
use Net::Telnet;
# set the required variables
my (@list,$server_list,$count);
my ($old_passwd,$new_passwd,$remote_login);
my ($DB_server,$DB_user,$DB_passwd,$telnet,$output);
# Get the required login and passwords
print "Enter the remote login :\n";
$remote_login = <>;
print "Enter the old password :\n";
$old_passwd = <>;
print "Enter the new password (Remember it should differ atleast in 3 CHAR than the old pas
swd) :\n";
$new_passwd = <>;
# Compare the Old and new password, if same exit
# else open the list and for each server on the list
# enter the remote_login and the old_passwd to login to the box and use the new_passwd to c
hange it
if ("$old_passwd" eq "$new_passwd")
{
print "Old and new password are same \n";
exit;
}
else
{
open(server_list,".servers") || die "couldn't open the file!\n";
@list = <server_list>;
$count = 0;
foreach $DB_server(@list){
$telnet = new Net::Telnet (Timeout =>10,
Errmode => 'die');
$telnet->open('dba1-sun');
$telnet->login("$remote_login","$old_passwd");
$telnet->cmd('passwd');
#$telnet->waitfor ('/\$ $/i');
$telnet->waitfor('/Enter existing login password: $/i');
$telnet->print("$old_passwd");
$telnet->waitfor('/New Password: $/i');
$telnet->print("$new_passwd");
$telnet->waitfor ('/Re-enter new Password: $/i');
$telnet->print("$new_passwd");
$output = $telnet->waitfor('/\$ $/i');
print $output;
$count++;
}
close(server_list);
}
Winners don't do different things
They do things differently
This one ask the user for the remote login, remote old_passwd and the new_passwd and change it in all the unix boxes. When ever I try to run it gives me an error saying time out (at the cmd(passwd))line. Anyways here is the code:
use strict;
use IO::File;
use DBI;
use Net::Telnet;
# set the required variables
my (@list,$server_list,$count);
my ($old_passwd,$new_passwd,$remote_login);
my ($DB_server,$DB_user,$DB_passwd,$telnet,$output);
# Get the required login and passwords
print "Enter the remote login :\n";
$remote_login = <>;
print "Enter the old password :\n";
$old_passwd = <>;
print "Enter the new password (Remember it should differ atleast in 3 CHAR than the old pas
swd) :\n";
$new_passwd = <>;
# Compare the Old and new password, if same exit
# else open the list and for each server on the list
# enter the remote_login and the old_passwd to login to the box and use the new_passwd to c
hange it
if ("$old_passwd" eq "$new_passwd")
{
print "Old and new password are same \n";
exit;
}
else
{
open(server_list,".servers") || die "couldn't open the file!\n";
@list = <server_list>;
$count = 0;
foreach $DB_server(@list){
$telnet = new Net::Telnet (Timeout =>10,
Errmode => 'die');
$telnet->open('dba1-sun');
$telnet->login("$remote_login","$old_passwd");
$telnet->cmd('passwd');
#$telnet->waitfor ('/\$ $/i');
$telnet->waitfor('/Enter existing login password: $/i');
$telnet->print("$old_passwd");
$telnet->waitfor('/New Password: $/i');
$telnet->print("$new_passwd");
$telnet->waitfor ('/Re-enter new Password: $/i');
$telnet->print("$new_passwd");
$output = $telnet->waitfor('/\$ $/i');
print $output;
$count++;
}
close(server_list);
}
Winners don't do different things
They do things differently