LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 04-30-2017, 12:12 PM   #1
geekslinux
Member
 
Registered: Jun 2013
Posts: 63

Rep: Reputation: Disabled
Password reset for multiple users script in AIX


Below script has user names in text file as input. For this script, some users password reset is working and for others password is not reset. Need your help in fixing this script. All are local system user accounts.

Code:
#!/bin/ksh
for i in `cat users.txt`
do
if[`id $i >/dev/null 2>&1;echo $?` -eq 0]
then
echo $i:$i
echo "$i:$i" | chpasswd -c
chesec -f /etc/security/lastlog-a "unsuccessful_login_count=0" -s $i
chuser account_locked=false $i
else
     printf "user: $i does not exist on this system\n"
fi
done

Last edited by geekslinux; 05-01-2017 at 05:44 AM.
 
Old 04-30-2017, 03:43 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by geekslinux View Post
Below script has user names in text file as input. For this script, some users password reset is working and for others password is not reset. Need your help in fixing this script. All are local system user accounts.
Code:
#!/bin/ksh
for i in `cat users.txt`
do
if[`id $i >/dev/null 2>&1;echo $?` -eq 0]
then
echo $i:$i
echo "$i:$i" | chpasswd -c
chesec -f /etc/security/lastlog-a "unsuccessful_login_count=0" -s $i
chuser account_locked=false $i
else
     printf "user: $i does not exist on this system\n"
fi
done
Please use CODE tags when posting scripts. And we'll be happy to help...when you actually tell us what error(s)/message(s) you're seeing, what diagnostic information you have, etc. "Not reset" for some, doesn't tell us anything. What's the differences between the accounts that work and the ones that don't? Have you run the script with any sort of debugging? Tried to run the commands manually on those that didn't work, to see what happened???
 
Old 05-01-2017, 05:43 AM   #3
geekslinux
Member
 
Registered: Jun 2013
Posts: 63

Original Poster
Rep: Reputation: Disabled
This is the output of the script. NB the users are there but not sure from where it fetches "User x does not exist". For some users when they gave username and password they were able to login. For certain users when they enter password it says "permission denied"
Code:
> ksh -x password-reset.ksh
+cat users.txt
+id ab123
+ 1> /dev/null 2>& 1
+echo 0
+[0 -eq 0]
+echo ab123:ab123
ab123:ab123
+chpasswd -c
+echo ab123:
3004-687 User "ab123" does not exist
+chsec -f /etc/security/lastlog-a unsuccessful_login_count=0-s ab123
+chuser account_locked=false ab123
+id ac234
+1> /dev/null 2>& 1
+echo 0
+[0 -eq 0]
+echo ac234:ac234
ac234:ac234
+chpasswd -c
+echo ac234:
3004-687 User "ac234" does not exist
+chsec -f /etc/security/lastlog-a unsuccessful_login_count=0-s ac234
+chuser account_locked=false ac234

Last edited by geekslinux; 05-01-2017 at 07:54 AM.
 
Old 05-01-2017, 07:30 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by geekslinux View Post
This is the output of the script. NB the users are there but not sure from where it fetches "User x does not exist". For some users when they gave username and password they were able to login. For certain users when they enter password it says "permission denied"
Code:
> ash -x password-reset.ksh
+cat users.txt
+id ab123
+ 1> /dev/null 2>& 1
+echo 0
+[0 -eq 0]
+echo ab123:ab123
ab123:ab123
+chpasswd -c
+echo ab123:
3004-687 User "ab123" does not exist
+chsec -f /etc/security/lastlog-a unsuccessful_login_count=0-s ab123
+chuser account_locked=false ab123
+id ac234
+1> /dev/null 2>& 1
+echo 0
+[0 -eq 0]
+echo ac234:ac234
ac234:ac234
+chpasswd -c
+echo ac234:
3004-687 User "ac234" does not exist
+chsec -f /etc/security/lastlog-a unsuccessful_login_count=0-s ac234
+chuser account_locked=false ac234
So you're running a ksh script with ash? Why? And as asked previously, what happens when you take one of the users you're having problems with, and run the script commands manually??
 
Old 05-01-2017, 08:47 AM   #5
geekslinux
Member
 
Registered: Jun 2013
Posts: 63

Original Poster
Rep: Reputation: Disabled
Sorry. It's a typo, I am running it as ksh. When I reset the password manually it works for the user. But resetting using script it's not working. It's only for few users across 10 servers where I run the script. Not all the users have this problem.
 
Old 05-01-2017, 08:56 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by geekslinux View Post
Sorry. It's a typo, I am running it as ksh. When I reset the password manually it works for the user. But resetting using script it's not working. It's only for few users across 10 servers where I run the script. Not all the users have this problem.
Then the problem isn't in the script; there's a difference in the users, somewhere.
Quote:
Originally Posted by geekslinux
NB the users are there but not sure from where it fetches "User x does not exist".
That's the output from a command...telling you it can't find that user ID. Aren't you providing the input list of users? Have you checked it for control/whitespace characters? There's obviously something wrong with the input data, or a difference between the users that work and don't.
 
Old 05-01-2017, 09:14 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
if[`id $i >/dev/null 2>&1;echo $?` -eq 0] can be definitely simplified:
Code:
if id $i >/dev/null 2>&1; then
...
else
   printf "user: $i does not exist on this system\n"
fi
next, that kind of for loop is not suggested, because it won't work properly in some cases.... but it depends on the input file you have.

Are these users local on that host?
 
Old 05-01-2017, 09:24 AM   #8
geekslinux
Member
 
Registered: Jun 2013
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. The users are all local users and they are available in the server. It works if I reset the password manually. The text file format is as follows
ab123
cd234

Also checked for white spaces nothing found.
 
Old 05-01-2017, 06:43 PM   #9
DukeSSD
Member
 
Registered: Sep 2007
Posts: 90

Rep: Reputation: 20
How did you check for white spaces?

# cat -???
 
Old 05-02-2017, 12:31 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
for me it looks very strange:
id reported user exists, chpasswd reported user does not exist.
did you try it without script (I mean the same user, same commands)?
you can also try to write a simple script:
Code:
#!/bin/ksh

username=something
id $username
echo "$username:$username" | chpasswd -c
chesec -f /etc/security/lastlog-a "unsuccessful_login_count=0" -s $username
chuser account_locked=false $username
to check if that work...
 
Old 05-02-2017, 09:42 AM   #11
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi geekslinux,

There seem to be some inconsistencies in your output, which makes it hard to see what's going on here. For example, the script says:

Code:
chesec -f /etc/security/lastlog-a "unsuccessful_login_count=0" -s $i
but the output says:

Code:
+chsec -f /etc/security/lastlog-a unsuccessful_login_count=0-s ab123
with no space before the "-s". If you're copying and pasting, this seems very strange.

In any case, to me it looks like there might be something funny in the script with the "echo" statements (possibly a special character or something). The code:

Code:
echo $i:$i
echo "$i:$i" | chpasswd -c
looks like it should echo the same information, but in the output this differs:

Code:
+echo ab123:ab123
ab123:ab123
+chpasswd -c
+echo ab123:
Any idea why this might be? I'd suggest you look carefully at the second "echo" for anything strange.

Good luck!

Clifford
 
Old 05-02-2017, 12:53 PM   #12
geekslinux
Member
 
Registered: Jun 2013
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thank you all. Yes cliff you are right

It was a typo error echo "$i:$" was there in the file as echo .$i:$i. this caused problems in the script. Now it works fine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell script for creating multiple users with password James0806 Linux - Newbie 3 04-11-2016 06:10 PM
[SOLVED] Script to remove users from a group from multiple AIX servers aswani5858 AIX 8 01-08-2015 12:14 PM
Password ageing for existing AIX users szahri AIX 1 04-12-2005 01:44 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 09:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration