LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-12-2012, 09:28 AM   #16
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled

@druuna
Here is what am doing.
I have made my other commands inactive in my original script except for the part where it generates the stripped file of user names and their status (active or inactive) as I have mentioned in my tables above.

Now i have copied your portion as another script. The stripped file is mentioned at the end of your script. All it does is create users.rogue and not the list of inactive users. active users am not concerned with.
In user.rougue file, I noticed that a user which was active and present in db file and etc did get listed. Two users that were inactive were not listed. So this list is good. But then why the other two files are not created. I used "find" but then stopped it. I used locate but no good. Is it that it is working or not. I believe it is not working
 
Old 11-12-2012, 10:42 AM   #17
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
okay ..its working as I had to specify different columns in <<{ _[$1] = _[$1]" "$2 } >> as <<{ _[$1] = _[$3]" "$5 }>> but....for some reason, it is reflecting both inactive users existing in db and etc/passwd and only existing in db in the same file users.inactive.db.only. Why ?
 
Old 11-12-2012, 11:07 AM   #18
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
I'm guessing that the db.users.list layout is different then described by you in post #1 and #4. Here are the 2 input files I used to test with:
Code:
$ cat passwd
root:x:0:0:root:/root:/bin/bash
userC:x:101:101:user2,,,,:/home/user2:/bin/bash
userF:x:105:105:user5,,,,:/home/user5:/bin/bash
userG:x:106:106:user6,,,,:/home/user6:/bin/bash
userH:x:107:107:user7,,,,:/home/user7:/bin/bash
Layout is the same as a regular /etc/passwd file. Made roughly to look like your layout described in post #4


Code:
root active
userB active
userC inactive
userD active
userE inactive
The db.users.list. A space is used as separator, do mind that active/inactive is case sensitive and that there are no blanks at the end of the lines.


If I run the script I posted in post #9 (using passwd instead of /etc/passwd), I get this:
Code:
$ ./user.status.sh 
$ ls -l users.*
-rw-r----- 1 druuna druuna  6 nov 12 18:01 users.inactive.db.only
-rw-r----- 1 druuna druuna  6 nov 12 18:01 users.inactive.in.both
-rw-r----- 1 druuna druuna 18 nov 12 18:01 users.rogue
$ cat users.rogue 
userF
userG
userH
$ cat users.inactive.db.only
userE
$ cat users.inactive.in.both 
userC
Which is exactly the output you described in post #4.
 
Old 11-12-2012, 11:35 AM   #19
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
rogue user file gets created but the other two do not get created on the production environment. rogue user files is correct.

in my test environment....user.rougue file gets created an but then then two inactive users i have are reflecting in the inactive users only in db file and the inactive user common in both files does not get created.

Do i make sense
Is the columns the cause here
 
Old 11-12-2012, 11:48 AM   #20
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
my db file in actual looks like this

1 034 james nathen active
2 035 bobby saen active
3 036 jimmy waso inactive
4 037 tony jackson inactive

I strip it to another file Xdb
james active
bobby active
jimmy inactive
tony inactive

I specify this Xdb file at the end of your script.

Here is what it looks like

#! /bin/bash

CMD="use itTools; select usernames.DataTelid, usernames.username, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid;"

mysql --host= --user= -p -e "$CMD" > /tmp/db

awk '{print $3" " $5}' /tmp/db | sort > /tmp/Xdb

awk 'BEGIN {

FS = "[: ]"

while ( ( getline < "/etc/passwd" ) > 0 ) _[$1] = $1

}

{ _[$1] = _[$3]" "$5 }

END {

for ( i in _ ) {

if ( _[i] !~ / active/ ) {

if ( i ~ _[i] ) { print i > "/tmp/rogueu" }

if ( _[i] ~ /^ inactive/ ) { print i > "/tmp/inactivedb" }

if ( _[i] ~ /. inactive/ ) { print i > "/tmp/inactivebt" }

}

}

}' /tmp/Xdb

exit 0

---------- Post added 11-12-12 at 11:49 AM ----------

@druuna please check above
 
Old 11-12-2012, 02:30 PM   #21
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Assuming that you did provide an accurate example this time, the above can be simplefied to:
Code:
#!/bin/bash

CMD="use itTools; select usernames.DataTelid, usernames.username, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid;"

mysql --host= --user= -p -e "$CMD" > /tmp/db.users.list

awk 'BEGIN { 
  FS = "[: ]"
  while ( ( getline < "/etc/passwd" ) > 0 )  _[$1] = $1 
}
{ _[$3] = _[$3]" "$5 } 
END { 
  for ( i in _ ) { 
    if ( _[i] !~ / active/ ) { 
      if ( i    ~ _[i] )         { print i > "users.rogue" } 
      if ( _[i] ~ /^ inactive/ ) { print i > "users.inactive.db.only" } 
      if ( _[i] ~ /. inactive/ ) { print i > "users.inactive.in.both" } 
    }
  }
}' /tmp/db.users.list

exit 0
The temp file is probably not needed (not tested):
Code:
#!/bin/bash

CMD="use itTools; select usernames.DataTelid, usernames.username, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid;"

awk 'BEGIN { 
  FS = "[: ]"
  while ( ( getline < "/etc/passwd" ) > 0 )  _[$1] = $1 
}
{ _[$3] = _[$3]" "$5 } 
END { 
  for ( i in _ ) { 
    if ( _[i] !~ / active/ ) { 
      if ( i    ~ _[i] )         { print i > "users.rogue" } 
      if ( _[i] ~ /^ inactive/ ) { print i > "users.inactive.db.only" } 
      if ( _[i] ~ /. inactive/ ) { print i > "users.inactive.in.both" } 
    }
  }
}' <( mysql --host= --user= -p -e "$CMD" )

exit 0

Last edited by druuna; 11-12-2012 at 02:32 PM.
 
Old 11-13-2012, 09:05 AM   #22
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
@druuna, I am going to test it in production today but could the silly mistake i made in my query result in the last two files not being created.
I say so because you have changed { _[$1] = _[$3]" "$5 } to { _[$3] = _[$3]" "$5 } which makes sense.

Another question, they way I was trying to achieve this goal in my very first script that i pasted, could you share how awful i was or put them in order for me. Cause i was going crazy at that moment.
 
Old 11-13-2012, 09:12 AM   #23
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
just to clarify, in you you recent script format, if i understand, you have taken my db file format and not the xdb.
 
Old 11-13-2012, 09:22 AM   #24
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
also there is something wrong. in either of the two fake databases i have made, your script does not create or go beyond creating rogue user list. what am i doing wrong
 
Old 11-14-2012, 10:57 AM   #25
piyush128k
Member
 
Registered: Jun 2012
Posts: 61
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
#! /bin/bash
CMD="use metadata; select usernames.SNo, usernames.DataTelid, usernames.UName, personaldata.ActiveInactive from usernames, personaldata where usernames.DataTelid=personaldata.DataTelid ORDER By usernames.UName, personaldata.ActiveInactive into outfile;"
mysql --host= --user= -p -e "$CMD" > /tmp/querydb
awk -F':' '{print $1}' /etc/passwd | sort > /tmp/userlist
sed s/Inactive/Passive/ /tmp/querydb >/tmp/parse
sed '/Active/d' /tmp/parse > /tmp/strpdb
awk '{print $3" " $5}' /tmp/strpdb | sort > /tmp/inactive
awk -F' ' '{print $3}' /tmp/querydb | sort > /tmp/usernames
comm -23 <(sort /tmp/userlist) <( sort /tmp/usernames) > /tmp/rogue
echo
echo This is the list of Inactive Users in Database
cat /tmp/inactive
echo
echo
echo This is the List of Rogue Users in Linux LDAP
cat /tmp/rogue
echo
echo
echo Thank you for your Time and Patience. I have reached solution on my own.
exit 0
 
  


Reply

Tags
pattern, split, split2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] AWK: split the file into multiple file and request for explanation of a known code cristalp Programming 4 11-23-2011 07:29 AM
[SOLVED] How can I split a file, without using 'split'? szboardstretcher Linux - Software 11 05-20-2011 02:43 PM
[SOLVED] Split a file to multiple file using awk or perl fad216 Programming 17 03-02-2011 06:15 AM
How to split file , .. awk or split ERBRMN Linux - General 9 08-15-2006 12:02 AM
mysqldump : Can I split the file up to 2GB max per file? Swakoo Linux - General 10 10-17-2005 04:13 AM


All times are GMT -5. The time now is 04:15 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration