clean passwd file based on db table (master)

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting clean passwd file based on db table (master)
# 1  
Old 06-22-2011
clean passwd file based on db table (master)

The purpose of this script is to scan the /etc/passwd file one line at a time comparing the usernames to the usernames found in a database table. I will later locked every account which is not in the database table.

I have export the userlist from the database in a file (/tmp/userlist). It should be faster than a sql check for every user.

The script works ok but my problem is that the script check also all system accounts!
how can disable it that the script didnīt check the system accounts like root,www-data and so on…

  rm -f $PASS_LOG && touch $PASS_LOG
  Isql –uHIDE –pwhatever –sprod –w 10 <<EOF >> /tmp/userlist
  Set nocount on
  Select name from db_workers where work is null
  for NAME in $(cut -d: -f1 "$PASSWORD_FILE" )
   passwd -S $NAME | grep "PS" >/dev/null
  if [ $STATUS -eq 0  ] ; then
  grep -i "$NAME" /tmp/userlist >/dev/null
  echo $STATUS2
  if [ $STATUS2 -eq 1 ] ; then
  echo $NAME >> $PASS_LOG

# 2  
Old 06-22-2011
If you think more in set notation and work in bulk, you can select one list from the DB, extract another from /etc/passwd, 'sort -u', and use the 'comm' command to compare the (sorted, unique) lists. Now you can have a missing list and an extra list to process automatically. You can even pipe it all together under bash <<(...), using 'sed' to do the list cleanup.
comm -23 <<(
  sed '...' /etc/passwd | sort -u
 ) <<(
  db_query_bits | sed '...' | sort -u
 ) | while read extra_id

Last edited by DGPickett; 06-22-2011 at 09:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

How can I replicate master master and master master MySQL databse replication and HA?

I have an application desigend in PHP and MySQl running on apache web server that I is running on a Amazon EC2 server Centos. I want to implement the master-master and master slave replication and high availability disaster recovery on this application database. For this I have created two... (0 Replies)
Discussion started by: Palak Sharma
0 Replies

2. Shell Programming and Scripting

Create table based on matched patterns

hi, i need help to create a table from an input file like this:- DB|QZX3 140 165 RT_2 VgGIGvGVR DB|QZX3 155 182 UT_1 rlgslqqLaIvlGiFT DB|QZX3 345 362 RT_1 GRKpllligS DB|ZXK6 174 199 RT_2 IstvtvptYlgEiatvkaR DB|ZXK6 189 216 UT_1 algtiyqLfLviGiLF DB|AZ264 15 17... (7 Replies)
Discussion started by: redse171
7 Replies

3. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

4. Web Development

MySQL Master-Slave Configuration: Don't Replicate a Row of a Table?

Anyone have a clue about this? I have checked the MySQL documentation and it does not seem possible to exclude a row of a table from replication between Master and Slave. It seems that replication in MySQL can only be managed at the table level, not at the row level. Does anyone know a work... (5 Replies)
Discussion started by: Neo
5 Replies

5. Emergency UNIX and Linux Support

Global update on a file based on a table

Hi, I 'd like to update the below highlighted values in a sample file based on the following table: 8283879A25918000000000005400000000000065629TTF3 8683884F40273000000000003900000000000047399TTF3 8883884FG0063000000000002600000000000031599TTF3... (7 Replies)
Discussion started by: er_ashu
7 Replies

6. UNIX for Advanced & Expert Users

Converting freebsd (5.2.1) master.passwd to Debian shadow

I'm trying to make this work, and it half works. Accounts with password hashes matching the old crypt(3) algorithm work just fine: JUpfW/w6jo6aw But accounts with longer password hashes preceded by $1$, such as the following, do not work: $1$iIcbppdP$HDyjJeVMGgJ.ovLsnjtTR.... (0 Replies)
Discussion started by: davidstvz
0 Replies

7. Shell Programming and Scripting

how to schedule no of jobs based on the value from the oracle table

Hi all, Please help me with the issue im facing. my client has a recquirement that unix script has to schedule the no.of jobs based on the value from the oracle table.for example if the table has a value of 20 the unix script has to schedule 20 able to write the script to get the value... (1 Reply)
Discussion started by: srikanths2s
1 Replies

8. UNIX for Advanced & Expert Users

Clean File

BeginDate 07/01/06 End: 07/31/06 Cust: A02991 - Burnham 0002000 5,829,773 145.3 0009701 4,043,850 267.3 2005000 286,785.13 100.0 BeginDate 07/01/06 End: 07/31/06 Cust: A01239 - East Track PSE Index A 0009902 317,356.82 890.2 0020021 ... (5 Replies)
Discussion started by: kris01752
5 Replies

9. BSD

Migrating the master.passwd

I am migrating the passwd file to an new server. What commands do I need to run to make sure the file will work on the new server. (0 Replies)
Discussion started by: rbizzell
0 Replies
Login or Register to Ask a Question