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

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need output in one line and filter servers, which has account expired or password exipred
# 1  
Old 10-16-2019
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

for hosts in `cat servers.txt`;
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'

out put giving from my script.......................
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 closed by remote host.

I am looking in below format --------------------------------------
IP hostname   password-length
IP password expired
Ip password expired
IP hostname  password length

Last edited by vbe; 10-16-2019 at 05:24 AM.. Reason: code tags please
# 2  
Old 10-16-2019
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.
# 3  
Old 10-16-2019
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

# 4  
Old 10-16-2019
Thanks for clarifying.

I guess I missed that in your post, reading and responding too fast.
# 5  
Old 10-16-2019
I tried to create script, now getting result approx 80%. now looking your help to get 100% result.

for server in `cat servers.txt`;
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"

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 abc02 5

Last edited by yash_message; 10-16-2019 at 11:39 AM..
# 6  
Old 10-16-2019
Added file "servers.txt" to read from.

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!

Last edited by RudiC; 10-16-2019 at 04:36 PM..
# 7  
Old 10-16-2019
Thanks for reply.

I am getting below error.

for server in `cat servers.txt`;
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

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)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Solaris 11 user account login expired

Hi everyone Please i need urgent help... I have installed solaris 11 using live media.. then i installed sunray.. every thing is fine.. but after system reboot i am unable to login on server on GUI it gives account expired error or some time authentication failed... but i can log in through... (11 Replies)
Discussion started by: amk
11 Replies

2. Solaris

Never Expired for root password

Never expired for root password Guy's I want to change the setting to keep the root password to be nerved expired! Please advice with the sitting! (9 Replies)
Discussion started by: top.level
9 Replies

3. UNIX for Advanced & Expert Users

password expired

Hi When i try to login with my username/password i get the following message 'Password for user 'lmathew' has expired - use passwd(1) to update it' please let me know what to do Thanks in advane Ammu (2 Replies)
Discussion started by: ammu
2 Replies

4. UNIX for Dummies Questions & Answers

How to reactivate expired account in Linux as a root user

I am an administrator of a Red Hat Enterprise Linux system. Now one account expired. I wonder how to reactivate the account. Thanks (2 Replies)
Discussion started by: cy163
2 Replies

5. AIX

HMC User account expired - What now?

I've created an hmc user account for our developers and set a pawword expiry to 30 days. Trouble is when the password expires they are asked to change it in the WebSM gui but it returns an error "XXXX check log file /var/websm/data/....log" which doesn't exist. I've tried resetting the password... (0 Replies)
Discussion started by: backslash
0 Replies

6. Solaris

expired root password

We have expiration set on the root password for 30 days. the only way to login as root remotley is login as another user and then su as root. I logged in to the machine today tried to su as root, and got the message password has expired, use passwd to change but i cant get in as root.. If... (1 Reply)
Discussion started by: csaunders
1 Replies

7. UNIX for Advanced & Expert Users

Root account is expired

Hi all, I am using redhat linux version 9 .I am unable to login to the system and i am getting a warninig sorry root account is expired . How can i activate the account. (2 Replies)
Discussion started by: mallesh
2 Replies

8. UNIX for Dummies Questions & Answers

prompting for account that expired

I have this problem. Two accounts in an aix. Account A expired and it would auto prompt for new password when the user failed to log in, but Account B would not prompt for the new password. Instead it will only display "your account is expired. Please contact your administrator". I would like to... (1 Reply)
Discussion started by: mayyap
1 Replies

9. AIX

AIX Non Expired Password

Hi, I am into production support and handling some of the AIX servers. We are planning to have a user id on a AIX system with non-expired password. Now the question is that if I have a non expired password then I cannot do a interactive login to AIX machine ( i:e cannot do Telnet ,SSH etc)... (0 Replies)
Discussion started by: siddhhuu
0 Replies
Login or Register to Ask a Question

Featured Tech Videos