Sponsored Content
Operating Systems Linux Red Hat Change password of linux servers remotely Post 302374911 by renuka on Wednesday 25th of November 2009 10:12:50 PM
Old 11-25-2009
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...
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

using ssh change password remotely?

Is it possible to change the password using a shell script, I want to remotely connect to a computer and then change password without manual intevention. Thanks in Advance Rishi (4 Replies)
Discussion started by: RishiPahuja
4 Replies

2. Shell Programming and Scripting

How To Read A File Remotely Without A Password?

Many thanks to anyone who can help me solve this problem I am having: I am working on an HP-UX system version B.11.11 and I have been tasked with finding a way to read a file on a remote server (cat, grep, etc.) using a specific userID without copying it or moving it to the local machine. ... (0 Replies)
Discussion started by: Korn0474
0 Replies

3. UNIX for Advanced & Expert Users

change passwd remotely in solaris 10

i'm trying to change passwd remotely in unix (solaris) and tried using "expect" but it is not working. Any ideas to change the passwd remotely using a shell script? (1 Reply)
Discussion started by: pharos467
1 Replies

4. Shell Programming and Scripting

Script:Change password on 1000+ servers

Hello Folks Scenario : I have a linux box (expect tool installed) which connects to 1000+ other boxes (either Solaris or AIX or Linux ) with a specific id and password using SSH. I now wish to write a script (Shell and/or expect and/or Python) which will change this existing password to a... (1 Reply)
Discussion started by: ak835
1 Replies

5. Shell Programming and Scripting

Change root password remotely

Hi All, Hope you all doing well...!!! First of all i will like to share few information about my network. I have a network of 50 solaris servers sample IPs are (10.2.135.1 to 10.2.135.50).. i have created trust for root user of servers 1(10.2.135.1) in all other servers, that is i have shared... (4 Replies)
Discussion started by: varunksharma87
4 Replies

6. Shell Programming and Scripting

Shell script to change the password on multiple servers in linux

Can any one please let me know the shell script to change the password for a particular user on multiple linux servers. (2 Replies)
Discussion started by: s_madras
2 Replies

7. Shell Programming and Scripting

How to change passwords for User accounts on multiple UNIX/Linux machines remotely?

Hello Experts, Need some direction on creating shell script for following environment: We have about 20 people in the team working as Oracle DBA's (sysdba's and appdba's). Total Servers which is a mix of Unix and Linux are 200. We do not have Root user access on any of the servers and... (3 Replies)
Discussion started by: sha2402
3 Replies

8. Shell Programming and Scripting

A script to change password for all other servers

Hey Gurus, I have this requirement to change the password for other servers remotely from one server. So, I installed public keys on all servers and wrote the following script to do the job. Something appears to be wrong with my loop, as it only changes one server and ignores the rest. I'm... (24 Replies)
Discussion started by: Hiroshi
24 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Password sent via reset password email is 'weak' and won't allow me to change my password

I was unable to login and so used the "Forgotten Password' process. I was sent a NEWLY-PROVIDED password and a link through which my password could be changed. The NEWLY-PROVIDED password allowed me to login. Following the provided link I attempted to update my password to one of my own... (1 Reply)
Discussion started by: Rich Marton
1 Replies
lindex(n)						       Tcl Built-In Commands							 lindex(n)

__________________________________________________________________________________________________________________________________________________

NAME
lindex - Retrieve an element from a list SYNOPSIS
lindex list ?index...? _________________________________________________________________ DESCRIPTION
The lindex command accepts a parameter, list, which it treats as a Tcl list. It also accepts zero or more indices into the list. The indices may be presented either consecutively on the command line, or grouped in a Tcl list and presented as a single argument. If no indices are presented, the command takes the form: lindex list or lindex list {} In this case, the return value of lindex is simply the value of the list parameter. When presented with a single index, the lindex command treats list as a Tcl list and returns the index'th element from it (0 refers to the first element of the list). In extracting the element, lindex observes the same rules concerning braces and quotes and backslashes as the Tcl command interpreter; however, variable substitution and command substitution do not occur. If index is negative or greater than or equal to the number of elements in value, then an empty string is returned. The interpretation of each simple index value is the same as | for the command string index, supporting simple index arithmetic and indices relative to the end of the list. If additional index arguments are supplied, then each argument is used in turn to select an element from the previous indexing operation, allowing the script to select elements from sublists. The command, lindex $a 1 2 3 or lindex $a {1 2 3} is synonymous with lindex [lindex [lindex $a 1] 2] 3 EXAMPLES
lindex {a b c} -> a b c lindex {a b c} {} -> a b c lindex {a b c} 0 -> a lindex {a b c} 2 -> c lindex {a b c} end -> c lindex {a b c} end-1 -> b lindex {{a b c} {d e f} {g h i}} 2 1 -> h lindex {{a b c} {d e f} {g h i}} {2 1} -> h lindex {{{a b} {c d}} {{e f} {g h}}} 1 1 0 -> g lindex {{{a b} {c d}} {{e f} {g h}}} {1 1 0} -> g SEE ALSO
list(n), lappend(n), linsert(n), llength(n), lsearch(n), lset(n), lsort(n), lrange(n), lreplace(n), string(n) | KEYWORDS
element, index, list Tcl 8.4 lindex(n)
All times are GMT -4. The time now is 08:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy