Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
#! /bin/bash
CMD="use metadata; select * from usernames; select * from personData; select usernames.SNo, usernames.DataTelid, usernames.UName, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid into outfile '/tmp/querydb';"
exec &> /tmp/final
cat /tmp/querydb|grep Inactive
awk -F':' '{print $1}' /etc/passwd | sort > /tmp/userlist
diff /tmp/querydb /tmp/userlist

Three files created. Querydb file has the results of the query which is a well formatted form. Userlist file has only the usernames stripped out from the /etc/passwd. This /etc/passwd is having the names of all users who login to the lab. So the Linux machine is the authenticating server.

Final file is supposed to have difference of userlist file as compared to querydb file. What is happening right now is that because it goes line by line it mentions the content from both files. I just need the final file to have the Inactive user from querydb (for which I have the cat command) but furthermore

  1. if the user in userlist exists in querydb but is "active" then I don't need to mention it
  2. if the user in userlist exists in querydb but is "inactive" then I need to mention it and label it as Inactive
  3. if the user in userlist does not exist in querydb then I need to label it as Rogue
share|improve this question
It would be easier if you included or posted somewhere example data files; we cannot re-run your script. Also, I have the impression that some commands are missing. – January Oct 22 '12 at 16:42
I have no idea what you're asking. Some sample input and output would definitely help. – Gilles Oct 22 '12 at 22:17

closed as too localized by manatwork, jasonwryan, rahmu, Renan, Gilles Oct 22 '12 at 22:17

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Although I am not entirely sure whether I understand you clearly, here is how I would deal with your problem:

diff file1 file2 | grep '^[<>]' | sed "s/^> \(.*\)/\1 Rogue/;s/^< \(.*\)/\1 Inactive/"

Entries missing in file1 (but present in file2) will be labeled as "Rogue", entries missing in file2 (but present in file1) will be labeled as "Inactive".

share|improve this answer
Thank you for the suggestion. Will try it – piyush19k Oct 23 '12 at 13:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.