Change password of linux servers remotely | Unix Linux Forums | Red Hat

  Go Back    


Red Hat Red Hat is the world's leading open source technology solutions provider with offerings including Red Hat Enterprise Linux (RHEL), Fedora, open source applications, security and systems management, virtualization, and Services Oriented Architecture (SOA) solutions.

Change password of linux servers remotely

Red Hat


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-25-2009
renuka renuka is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 13 April 2010, 1:44 AM EDT
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Change password of linux servers remotely

Hi,
I am very bad at scripting. I need help from scripting experts...
I need to change password of around 100 linux remote servers. I have been given a script for changing the password that automates the task. however I do not understand the usage and meaning of the script, the script is an expect script. Could some one please help me understand the script and how to use it? here is the script...

Code:
#!/usr/bin/expect
# usage: runcmd <command> <password>
#
# NB: be sure to surround the command with double quotes
# if the command string is more than 1 word
#
set timeout 30
set fid [open /root/utilz/scripts/hosts r]
set contents [read -nonewline $fid]
close $fid
set cmd [lindex $argv 0]
set password [lindex $argv 1]
set newpass [lindex $argv 2]
foreach host [split $contents "\n"] {
        spawn ssh -l root $host
        expect {
                "assword:" {
                        send -- "$password\r"
                }
                "you sure you want to continue connecting" {
                        send -- "yes\r"
                        expect "assword:"
        send -- "$password\r"
                }
        }
        expect "#"
        send -- "$cmd\r"
        expect "assword:"
        send "$newpass\r"
        expect "assword:"
        send "$newpass\r"
        expect "#"
        send -- "exit\r"


Last edited by pludi; 11-26-2009 at 01:06 PM.. Reason: code tags, please...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to change root password using shell script with standard password kurva Shell Programming and Scripting 2 02-25-2009 01:35 AM
change passwd remotely in solaris 10 pharos467 UNIX for Advanced & Expert Users 1 09-15-2008 10:58 AM
How To Read A File Remotely Without A Password? Korn0474 Shell Programming and Scripting 0 03-12-2008 11:55 AM
using ssh change password remotely? RishiPahuja UNIX for Advanced & Expert Users 4 09-26-2007 10:33 AM



All times are GMT -4. The time now is 03:03 AM.