![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 02:06 PM.. Reason: code tags, please... |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 02:35 AM |
| change passwd remotely in solaris 10 | pharos467 | UNIX for Advanced & Expert Users | 1 | 09-15-2008 11:58 AM |
| Administer servers remotely with Web Console | Linux Bot | UNIX and Linux RSS News | 0 | 05-02-2008 05:20 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 11:33 AM |