Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I change the root password on all 10 of my servers? 1

Status
Not open for further replies.

farley99

MIS
Feb 12, 2003
413
US
How can I change the root password on all 10 of my servers?
 
Assuming that you want to do it remotely and with
some degree of error control you could use expect
to drive ssh sessions with a set of commands to be
executed once logged in.

If you want an example of something like this
I'll provide one.

 
Code:
#!/usr/bin/tclsh
package require Expect

####functions#########
proc getIn {msg} {
stty -echo
       puts -nonewline "INPUT:$msg "
       flush stdout
       set ans [gets stdin]
       stty echo
       return ans
}

#exp_internal 1
set timeout 125
#first and second args are remote hostname and username.
set username [lindex $argv 0]
set prompt ".*@.*"
set rootprompt "root@.*"
####main()###########

   foreach poss [lrange $argv 1 [llength $argv]] {
                spawn -noecho deslogin $username@$poss
                lappend ids $spawn_id
               

                expect {
       
                           -re ".*ass.*hras.*" {
                            send "[getIn \"Enter password for $poss\"]\r"
                            expect -re $prompt {
                                               send "TERM=vt100\r"
                                               send "su root\r"
                                               expect -re ".*assw.*" {
                                                          send "[getIn \"Root password please\"]\r"
                                                          expect -re "$rootprompt" {
                                                                     send "passwd\r"
                                                                     expect -re ".*ew.*assw.*" {
                                                                                set new [getIn "\New password\"]
                                                                                send "$new\r"
                                                                                expect -re ".*enter.*assw.*" {
                                                                                            send "$new\r"
                                                                                            expect -re "$rootprompt" {interact -i $spawn_id}
                                                                                 }                    
                                                                      }                                    
                                                           }                                                                                                              
                                                   }
                             }
                         }
                  }

    }

#remainder of script allows the user to interact with the spawnede sessions, switch back and forth, issues a keepalive, etc..



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top