Need output in one line and filter servers, which has account expired or password exipred

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

The password of users are stored as a cryptographic hash. Hence you cannot get the length of a users's password from the stored hash.

Neo, thanks for reply.
I need value from /etc/login.defs files only.

cat /etc/login.defs  |grep -i PASS_MIN_LEN |grep -v -i minimum

Thanks for clarifying.

I guess I missed that in your post, reading and responding too fast.

I tried to create script, now getting result approx 80%. now looking your help to get 100% result.

#!/bin/bash
for server in `cat servers.txt`;
do
hostname=`sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q -t xyz@${server} "hostname"`
paasword=`sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q -t xyz@${server} cat /etc/login.defs  |grep -i PASS_MIN_LEN |grep -v -i minimum |awk '{print $2}'`
echo -e  "$server \t\t\t$hostname  \t\t$paasword"
done

but out put coming like below....

.0.0.1 5 abc01
.0.0.2 5 abc02

there is removed first octate of ip. output is coming fine , if I comment #password variable

it should be come ..
10 .0.0.1 abc01 5
10.0.0.2 abc02 5

Try

while read server
   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 < servers.txt

Read from input file!

Thanks for reply.

I am getting below error.

#!/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.

sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q -t xyz@${server} awk -vHN="$(hostname)" "'/[mM]inimum/ {next} /PASS_MIN_LEN/{print HN, $2}'"  /etc/login.defs

Still looking suggestion.

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.

sshpass -p 'abc' ssh -o StrictHostKeyChecking=no -q xyz@${server} 'awk -v HN="$(hostname)" '\''/[mM]inimum/ {next} /PASS_MIN_LEN/{print HN, $2}'\'' /etc/login.defs'

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).