OK, thanks for the feedback. If you try running it with the '-x' flag to Bash, which will make it show you each step as it executes, where does it hang ? So you'd want to run bash -x ./pwchange.sh pwchange.dat and see the line it's freezing on.
@vbe, thanks for the follow up. ssh -n hangs too. but, here is something interesting though. When I comment out all the servers except one in the .dat file, this is what I get:
So, ssh is tried for each server, but it fails name resolution because obviously it doesn't know what to do with #, but it does attempt all of them and it does change that one server who is not commented out correctly. STRANGE! But, when I uncomment all the servers in the .dat file, then it hangs.
BTW, in this instance my .dat file looked like the following:
---------- Post updated at 02:52 PM ---------- Previous update was at 02:48 PM ----------
Last edited by rbatte1; 02-22-2017 at 07:56 AM..
Reason: Code tags
That at least is easy to explain. You can't really 'comment out' input. So what is happening is that 'ssh' is attempting to connect to the hosts whose names start with a hash symbol, and DNS resolution is failing for what are invalid hostnames. If you want them not to be considered by the script, you'd have to remove them entirely. Commenting out only works in scripts, and not in the input files handled by scripts (unless you yourself write the appropriate code to handle that).
In terms of the part of the script that is hanging, it does seem it's something to do with the actual core 'passwd' section itself. Before digging any further: if you manually try to run echo -e "TestPW12345!\nTestPW12345!" | passwd mchavoshi on the target server yourself at a Bash prompt, and not as part of a script, does it actually work, or does it hang even when you run it yourself ?
that command by itself on the command line works perfect. Please see below:
Moderator's Comments:
Please wrap all code, files, input & output/errors in CODE tags as in the rules.
It makes it far easier to read and preserves multiple spaces for indenting or fixed width data.
Last edited by rbatte1; 02-22-2017 at 07:57 AM..
Reason: Code tags again.
Id guess that passwd is refusing to take input from a non-terminal.
On *nix servers I find usermod(8) to be much more reliable for this sort of thing e.g.:
Note: if you use openssl passwd (i.e. no password on the command line).
It will prompt on the terminal for password and a verification which is preferable to hard-coding it in the script as it won't be visible to utilities like ps
Last edited by Chubler_XL; 02-21-2017 at 08:23 PM..
This User Gave Thanks to Chubler_XL For This Post:
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)