Large password lock script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Large password lock script
# 1  
Old 03-29-2011
Large password lock script

I am trying to create a script that will take a very large, tab delimited file and then lock accounts.

File headers look like this

id desc server pass sudo lock
test Test user server01 67 no no

"Test user" is under the desc column

Basically if pass column is greater than 60 and lock is no, I need it to ssh to the server in the server column field and lock the account in the id field.

I know i need to use if and awk but I am stumped and running short on time.
Also this needs to be in ksh

Thanks

Last edited by Gibby13; 03-29-2011 at 03:23 PM.. Reason: fixing columns
# 2  
Old 03-29-2011
You've got more columns than column names there, which is right?
# 3  
Old 03-29-2011
Fixed original post
# 4  
Old 03-29-2011
Quote:
Originally Posted by Gibby13
Fixed original post
You've still got 7 columns and 6 column names. Which is right?
# 5  
Old 03-29-2011
I think this will work



Code:
#!/bin/ksh
executeLine(){
  line="$@" 
  ID=$(echo $line|awk -Ft '{print $1}')
  SERVER=$(echo $line|awk -Ft '{print $3}')
  AGE=$(echo $line|awk -Ft '{print $4}')
  LOCKED=$(echo $line|awk -Ft '{print $5}')

if [ $AGE -ge 60 && $LOCKED = "no"]
        then
                ssh $SERVER passwd -l $ID
        else
                echo "User ID $ID does not meet lock requirements, did not lock ID"
fi
}

echo "Enter UAAS file" 
read FILE
 
while read -r line
do
        executeLine $line
done

---------- Post updated at 02:56 PM ---------- Previous update was at 02:53 PM ----------

Quote:
Originally Posted by Corona688
You've still got 7 columns and 6 column names. Which is right?

1 2 3 4 5 6
id desc server pass sudo lock
1 2 2 3 4 5 6
test Test user server01 67 no no
# 6  
Old 03-29-2011
Code:
awk -F\\t '(($NF=="no")&&($(NF-2)>60)){sub(/.*/,"yes",$NF)}1' OFS=\\t infile

---------- Post updated at 09:41 PM ---------- Previous update was at 09:36 PM ----------

Oh ...
ok, i see :


Code:
awk -F\\t '(($NF=="no")&&($(NF-2)>60)){print $3,$1}' infile | while read svr uid
do
ssh $svr passwd -l $uid
done

---------- Post updated at 09:48 PM ---------- Previous update was at 09:41 PM ----------

Code:
$ cat tst
test01  Test user       server01        57      no      no
test02  Test user       server02        67      no      no
test03  Test user       server03        57      no      no
test04  Test user       server04        97      no      yes
test05  Test user       server05        60      no      no
test06  Test user       server06        67      no      no
test07  Test user       server07        88      no      no
test08  Test user       server08        57      no      no
test09  Test user       server09        57      no      no
test10  Test user       server10        99      no      no
$ awk -F\\t '(($NF=="no")&&($(NF-2)>60)){print $3,$1}' tst | while read a b; do echo "ssh $a passwd -l $b"; done
ssh server02 passwd -l test02
ssh server06 passwd -l test06
ssh server07 passwd -l test07
ssh server10 passwd -l test10
$

... if you want to run it, just remove the echo part : change
Code:
echo "ssh $a passwd -l $b"

into
Code:
ssh "$a" passwd -l "$b"


Last edited by ctsgnb; 03-30-2011 at 10:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Lock password for 15 minutes

Hi, Can we configure Solaris-10 and Solaris-11, which can lock any user for 15 minutes after 5 unsuccessful logins ? I am trying to search, if it is possible but not able to find. Regards (1 Reply)
Discussion started by: solaris_1977
1 Replies

2. Shell Programming and Scripting

Script lock functionality

Hi All, My requirement is i have a script A.sh .When a person A runs the script A.sh it should get locked and person B should not run the script. i followed the below code f_script_lock() { process=$1 user=`ps -ef | grep -i "$process" | grep -i 'ksh' | awk '{print $1;}'` if ; then ... (1 Reply)
Discussion started by: mohanalakshmi
1 Replies

3. UNIX for Dummies Questions & Answers

How to Lock the Script?

Hi All, Seeking for your assistance on how to lock the script if it's running? meaning anybody can't run my script while it's running. Please advise, Thanks, (8 Replies)
Discussion started by: nikki1200
8 Replies

4. Shell Programming and Scripting

Lock the 2nd script!

Hi All, newbie here, is it possible to lock my second script? because my 1st script is still running. Ex. 1st run : 1st script.sh --> running..... 2nd run : 1st script.sh --> lock because the script is still running.. i don't have any idea how to do it. Please advise, Thanks,... (1 Reply)
Discussion started by: nikki1200
1 Replies

5. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

6. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

7. Solaris

Lock Password 3x times

Dear ALL, I have account to access to my server. If I type wrong password or wrong username 3x times then solaris will be automatically lock this user account. So, How to de-activated this policy..?? Best Regards Bejo:) (2 Replies)
Discussion started by: mbah_jiman
2 Replies

8. UNIX for Dummies Questions & Answers

Change Account to not lock account if password expires

I have access to 15+ UNIX boxes at work, and I do not consistently log onto all of them over time. When I do try to access one I havent been on in awhile, my account is locked as the password has expired. I need to request to the UNIX SA's that the password expiration is 90 days and that if it... (1 Reply)
Discussion started by: stringzz
1 Replies

9. Shell Programming and Scripting

Lock for this script

Hi, My requirement is to service a process and below is the script which i wrote for that and works fine, I have kept it in a crontab and running this everyminute, how do I lock this if its already running and i dont want to open if its running and not completed yet. The crontab need to run... (4 Replies)
Discussion started by: strunz
4 Replies

10. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies
Login or Register to Ask a Question