passwd -l script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passwd -l script
# 1  
Old 02-22-2005
passwd -l script

I need to lockout about 250 user accounts on a server. I figure on putting the user accounts to be locked out in a text file and the running a script to go through the file and run the "passwd -l useraccount" against the /etc/passwd file (yes, I am root as I do this).

Here is what I have so far:

#!/bin/sh
# BE CAUTIOUS!! This will modify the /etc/passwd file to lockout terminated
# employee accounts using the 'passwd -l useraccount' command.
# copy this to servername under the /etc directory. Make sure the
# text file that has the user accounts to be deleted is also copied to servername.

# create variables
TERMED="terminated"
# LOCATION_EMAIL="myemail@mycompany.com"
for GONE in `/etc/seeya`
do
echo "**********************************" > $TERMED
passwd -l $GONE
echo "This user account, "$GONE", is locked on `date +%m/%d/%y`." >> $TERMED
echo " " >> $TERMED

(do I put a 'done' statement here?)
#mail results of TERMED
#cat $TERMED |uuencode $GONE.wri | mailx -s "$GONE account locked" $LOCATION_EMAIL
# delete TERMED to make room for next on list.
# rm $TERMED

It seems pretty simple, but what if there is a useraccount in my list, but not in the /etc/passwd file? or vice-versa? other error messages?
Also, is my email statement right? I don't want 200+ individual emails, just one email showing the contents of $TERMED.

Thanks for the help. Smilie
# 2  
Old 02-22-2005
changes

It looks like I'm going to have to do a compare of two files, the /etc/passwd file and my file that has the list of userID's to lockout. The script flow should look like this:

1. compare lockout file to /etc/passwd
2. if a userID in the lockout file matches the username field in the /etc/passwd file, then
3. the 'passwd -l username' command is executed.
4. if there is no match, go to the userID next in the lockout file
5. it should loop until all of the userID's in the lockout are processed.

I will probably have to forget the shell script and attempt this with either a sed or awk script.
# 3  
Old 02-22-2005
I'm not sure how passwd -l works
This option does n't exists in AIX.
I'm not sure whether passwd -l is interactive.

Following is NOT TESTED. But you can follow on these lines.

Code:
#!/usr/bin/ksh

>TERMED

while read user
do

    grep "$user" /etc/passwd
    if test $? -eq 0
    then
       # do what you want to do ... run passwd -l ....
       if test $? -eq 0
       then
            echo "Locking user $user on `date` "  >> TERMED
       else
            echo "PROBLEM in Locking user $user on `date` "  >> TERMED
        fi
    fi

done < /etc/seeya

# send mail using TERMED file

# 4  
Old 02-23-2005
Thanks bhargav

bhargav,

Your code worked perfectly!

Thanks so much for your help!. Smilie Smilie Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

2. Shell Programming and Scripting

Script to generate passwd comb.

Hi I created a gnupg password which I later forgot clumsy enough (after a holiday). I can always create a new one but unfortunately I have some files on the computer that I encrypted with it and would like to access it. I remember parts of the password and was wondering what's the the best way to... (0 Replies)
Discussion started by: zaonline
0 Replies

3. Shell Programming and Scripting

Need script to monitor change in /etc/passwd

Hi All, From Audit point of view, I need to add a script to my production Solaris servers. That should be able to mail me, if any user is added or removed. That means, I should get a mail, what user is deleted or added in /etc/passwd, i.e. if there is a change in this file, I should be... (8 Replies)
Discussion started by: solaris_1977
8 Replies

4. Solaris

Solaris passwd script

Hello all, Since Solaris passwd does not have --stdin option can you advise how to change the password for 30 users with a script. The password can be the same one. I`ve tried already echoing, xargs, cat and similar. Thanks. ---------- Post updated at 04:04 AM ---------- Previous update... (0 Replies)
Discussion started by: click
0 Replies

5. Shell Programming and Scripting

Modify /etc/passwd via script

We have a business need to modify the /etc/passwd file every time a new user gets added, because the user ID begins with a zero. When you create the new user in smit, even if you put the leading zero in, it does not retain it when the entry is added. That being said, I need to create a script... (11 Replies)
Discussion started by: mshilling
11 Replies

6. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

7. Shell Programming and Scripting

passwd on a simple script

hi guys I am working on a script which is basically a menu for some linux operators... I need on this menu for the operators the option to change the password... This are 2 linux servers using Linux heartbeat. what I need is to change change the password using passwd command and replica... (10 Replies)
Discussion started by: karlochacon
10 Replies

8. Infrastructure Monitoring

need script for passwd , can't use expect tool

Hi , as others users here , i'm searching for a script which can automate "passwd" dialog . I saw threads about "expect tool" but on my platforms , "C" product isn't installed and i'm not the admin so i can't install it. is there another way to do it , with a "simple" shell script ??? ... (35 Replies)
Discussion started by: Nicol
35 Replies

9. Shell Programming and Scripting

passwd in shell script

Is there a way to change user password using passwd command in shell script? I don't want to use expect. Please help (8 Replies)
Discussion started by: corny
8 Replies

10. UNIX for Advanced & Expert Users

setting passwd in script

HP-UX 11 I currently have a script that is running useradd and passwd commands to automate setting up new users. It was originally designed so that passwd was run with -d -f to delete a passwd and force user to set passwd at next login. Now mgmt wants instead to set a first-time passwd and have... (2 Replies)
Discussion started by: LisaS
2 Replies
Login or Register to Ask a Question