I am running into few issues, please suggest me what I am missing.
I am running this script on a linux host.
Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo access to root with password less on all the server.
issue: /tmp/hostname.txt file contains list of IP addresses line by line, when I execute this script, I get the o/p of the first host successfully and stops executing right from that point.
# more userid
#!/bin/bash
while read line
do
ssh $line '(echo "`hostname` UID for User v7866 is `getent passwd v7866 | cut -f3 -d:`")' >> /tmp/output
done < /tmp/hostname.txt
#
#more /tmp/hostname.txt
10.10.7.182
10.10.7.173
10.10.7.143
#
ssh tries to read from the same standard input as your while loop, 'eating' your entire datafile.
Also, you don't need to re-open the same logfile 9,000 times to write 9,000 lines.
Also, the braces aren't necessary.
#!/bin/bash
while read line
do
ssh $line 'echo "`hostname` UID for User v7866 is `getent passwd v7866 | cut -f3 -d:`"' </dev/null
done < /tmp/hostname.txt > /tmp/output
I was able to run the script as suggested works fine !!!!
for ip_addr in $(cat hostname.txt); do
ssh ${ip_addr} "bash -s" < script_to_be_invoked
done
The only annoying part is, once the user ssh into the each server, I see banner is being displayed on the terminal, how do we remove that from the output.
Just map the ip addresses of your remote servers' with a unique name one by one and line by line in your /etc/hosts on the master server which can manage all your remote servers
can someone please suggest, I am trying to update user password on remote server. user who is trying to run this script have sudo rules setup with password less. I am not sure where I am missing here.
$ ssh -t 10.10.10.89 "bash -s" < 'sudo echo Welcome | passwd --stdin neen'
-bash: sudo echo Welcome | passwd --stdin neen: No such file or directory
$ ssh -t 10.10.10.89 "bash -s" < sudo echo Welcome | passwd --stdin neen
-bash: sudo: No such file or directory
Only root can do that.
$