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 testing the script with a test data file with about 5 servers in it. The data file is the command-line argument to the script. Can you please tell me what's wrong and how to fix it?
As always, I truly appreciate this community effort. You guys are truly awesome; thank you very much.
Last edited by vbe; 02-21-2017 at 04:03 PM..
Reason: code tags please
I think that this behaviour is being caused by the use of a 'while read' loop to drive the 'ssh' command. The way input is read in and processed in this particular script may not actually be what you'd expect. Instead of it looping nicely around, the entirety of your arguments end up being passed to 'ssh' in one glob, and it's just doing the first one.
Maybe try a 'for' loop instead ? So something like:
See if that works, and let us know how you get on.
Just checking, but are you running it with the filename as an argument ? e.g. ./script.sh serverlist.txt or something like that ? The script takes the first argument ($1) as the filename to be read and processed.
I ask becasue if you were just running ./script.sh on its own will never return a prompt, which is what you describe. In that usage case it would be sitting waiting for you to type in the input yourself, and would only proceed with execution after you did a Ctrl-D or otherwise indicated the end of input.
It's also possible of course that the issue is with the ssh or passwd parts of the script now as well. You may need different flags to passwd, something like passwd --stdin on a Red Hat-style system.
With the while loop, it did read the pwchange.dat file, but it only changed the password for one server. And I got the prompt back.
With the for loop, ctrl-D does nothing, but ctrl-C breaks out of the script and give me the prompt back w/o doing anything.
Also, my environment is a mix of Solaris 10 and Linux (RHEL & SUSE). My script with the while loop does change one password, it changes either Solaris or Linux server. So, looks like the ssh & passwd commands are both OK.
Last edited by rbatte1; 02-22-2017 at 07:55 AM..
Reason: Added CODE tags
So you havent tried ssh -n ... as I said ssh will read the first line but then it will expect things to coem from standard input unless you specify -n option
Hi,
I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command.
But, could not figure out how to do the same in shell script.
Could you please help me with the shell... (3 Replies)
I need run a command such as ps -ef |grep xxx on a batch of servers, how to write a script to run it without password? don't need go in each server to check?
Thanks (7 Replies)
I am having the 15 servers which need to do the monitoring
Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts.
Please help me to write the script so that it can login with username and... (5 Replies)
Hi,
I need to Change passwd for bulk servers using SSH script.
I have one server, from which i can reach all the servers without password via SSH.
There is some expect script, from which i can achieve it.
Can any one help me out here.
Thanks in advance.
Vicky (1 Reply)
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)
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... (0 Replies)
Hi Friends.
I am new to scripting now i want to change the root password using the script with standard password.
which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
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)
Hey..
I am new in scripting.. I know a little bit of scripting.. I am facing some problem.. I need to create a script using which I may log on to a server (e.g. ftp) with ID and password.. thus copy a particular file to a local dir.. the commands required to do that I do know.. I am able to do it... (1 Reply)