Shell script to ssh and change the passwords


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to ssh and change the passwords
# 1  
Old 01-13-2014
Shell script to ssh and change the passwords

Hi All,

I am trying to create a script with the help of while and expect loop to do the following:
1. script will pick up the servers one by one from server_list file and will do ssh to it.
2. for each server it will change the password of user test1.
3. script should also provide logs for each and every step

below is sample script which i have created (doesnot inlcude the password change part , since i want to first make sure script run correctly before inclusding password change commmand in to it).
Code:
cat -n test.sh
     1  #!/usr/bin/expect -f
set hosts [open server_list r]
     4  while {[gets $hosts host] >= 0}
     5  {
     6  #echo "connecting $server via ssh"
     7  spawn sh -p 56786 -l test1 $host
     8  expect "$"
     9  send "exit\r"
    10  expect eof
    11  }
    12  close $hosts

Code:
 
i am getting error as :
[root@VM172016001140 tmp]# bash -x test.sh
+ LOG=/tmp/changepassword.log
+ set hosts '[open' server_list 'r]'
test.sh: line 13: syntax error: unexpected end of file

can someone help in modifying this script to fulfill all the mentioned requirement.Smilie
# 2  
Old 01-13-2014
I'm not sure that you log snippet fits your code snippet as there's no LOG assignment in the code (or part of the code is overtyped due to e.g. <CR> chars at EOL). So I can't tell if there's e.g. an opening quote too many. Any how, in line 7, the ssh command lost one "s".
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Change user passwords using shell script

Hi, I want to change the password of unix users on a number of servers.My plan was to ssh to all the servers in a shell script and use the passwd command. I tried to do so but everytime i run it i get this error. ssh -x -n -l user1 host passwd Changing password for "user1" 3004-709 Error... (3 Replies)
Discussion started by: poojabhat
3 Replies

2. Shell Programming and Scripting

ssh and passwords

In my environment "SunOS - 5.10 Generic_142900-14 sun4v sparc SUNW,T5240" when I issue an ssh i get prompted for a password. I need to run an ssh in a script but is it possible to ready an encrypted password file or to pass the password in the script or configure it so that a particular user-id... (1 Reply)
Discussion started by: Harleyrci
1 Replies

3. UNIX for Dummies Questions & Answers

A shell script or software for generating random passwords

Hi, Is there an shell script/batch file to genarate random passwords which expires after a stipulated time period? Please suggest a software which does this for AIX and windows both else. Thanks. (5 Replies)
Discussion started by: dwiravi
5 Replies

4. UNIX for Dummies Questions & Answers

A shell script or any software to genarate random passwords

Hi, Is there a shell script or any software to genarate random passwords and the passwords expire automatically after a stipulated time period. Please suggest. (2 Replies)
Discussion started by: dwiravi
2 Replies

5. UNIX for Dummies Questions & Answers

Batch file to change all passwords

Hi all I am using tru64 Unix and I want to use batch file which makes me to change all user passwords at the same time ,instead of changing everyone separately. Please could anyone help me to do that. bye. (2 Replies)
Discussion started by: ahmedbashir
2 Replies

6. Shell Programming and Scripting

SSH - Passing Unix login passwords through shell scripts

Hi All , I need to call a script runscript_B.sh on server A, the runscript_B.sh script locating in server B. The runscript_B.sh in calls another script runscript_A on server A itself. it seend, i need to be connect from Server A to Server B using ssh. I have tryed like this in... (3 Replies)
Discussion started by: koti_rama
3 Replies

7. Shell Programming and Scripting

script to change passwords for the same user on multiple servers

I am trying to write a script to change passwords for the same user on multiple servers. My environment runs purely ssh / scp not rsh / rcp and therefore coping using rcp is not an option. I have been playing with expect to perform tasks but think there must be a better way. Has anyone got... (7 Replies)
Discussion started by: stolz
7 Replies

8. Solaris

Urgent !!! - Script to Change passwords in unix

I have SunOs 5.8. I need to change password using a unix shell script. I have tried to pipe the passwords to the passwd command but does not work. Pls provide a script to change passwds of a list of users using a shell script. ( I have also tried crypt() but did not work) The flow of the... (2 Replies)
Discussion started by: tofani
2 Replies

9. UNIX for Dummies Questions & Answers

Change NIS Passwords without dxaccounts/SAM?

Hi, if I am dialling in remotely it takes a long time to launch dxaccounts on Tru64 or SAM on our HP boxes. Can anyone tell me how to reset users NIS passwords without knowing their old password from the command line? When I use yppasswd it prompts me for the old password even though I am... (1 Reply)
Discussion started by: sjmolloy
1 Replies
Login or Register to Ask a Question