I have 500 servers, in which I am looking to get hostname and password length information.
when I am trying to run script(which I build), in which shows output in one line below and asking to reset password and also some of the servers does not give output.
Please help
#!/bin/bash
for hosts in `cat servers.txt`;
do
echo "$hosts---"
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q -t xyz@$hosts 'hostname; cat /etc/login.defs |grep -i PASS_MIN_LEN |grep -v -i minimum'
done
out put giving from my script.......................
192.168.0.3---
xyz-name
PASS_MIN_LEN 5
192.168.0.4---
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user xyz.
Changing password for xyz.
(current) UNIX password: Connection to 192.168.0.1 closed by remote host.
192.168.0.2---
I am looking in below format --------------------------------------
IP hostname password-length
IP password expired
Ip password expired
IP hostname password length
#!/bin/bash
for server in `cat servers.txt`;
do
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q -t xyz@${server} awk -v"HN=$(hostname)" '/[mM]inimum/ {next} /PASS_MIN_LEN/{print HN, $2}' /etc/login.defs
done
awk: fatal: cannot open file `{next}' for reading (No such file or directory)
awk: fatal: cannot open file `{next}' for reading (No such file or directory)
A level of quoting disappears (because your local shell interprets it first) when you put code over ssh / sshpass. You need to quote some of your quoting.
An awk command over ssh is tricky, because you need two levels of 'single quotes' for the $-expressions.
The previous " " lets already the local shell evaluate the $-expressions - certainly not wanted.
The '\'' makes a ' within ' '
Now the syntax is okay, but I have not checked what the awk command does.
I have omitted the -t (it does some effort to satisfy bad remote applications, but it can have bad side effects).