Need some MySQL query help...

From: Scott V Nipp (sn4265_at_sbc.com)
Date: 01/20/04


To: dbi-users@perl.org
Date: Tue, 20 Jan 2004 09:48:54 -0600


        I am working on a set of Perl scripts, along with some PHP web
pages, to help organize and automate user account creation in a large HP-UX
environment. I am currently writing a few scripts to gather all of the
existing user account data from every system and populate a couple of
database tables. One feature I am working on is to have a history table to
track all changes to user accounts.
        I am currently working on the logic of the script that populates the
database tables and what I am attempting to do is compare the existing
passwd entry to the current database entry. The Primary Key on the current
table (acct_db) is a combination of userID and hostname. I want the query
to match the Primary Key, and compare all of the data in the passwd file to
the data in this table. Assuming the data is all a match, nothing happens,
the script simply proceeds to the next entry. If however there is a
difference, the script should delete the entry and populate this same entry
into the history table (acct_hist) and also insert the new data into the
current table.
        This is where I am currently running into problems. I am not sure
exactly how to test for inequality of all the variables in the passwd file.
I was hoping to have a single MySQL query do the test in order to use it to
help simplify the Perl code. The SELECT statement is where I think I am
going wrong here. Here is the code loop that processes the passwd file
data:

while ($file = readdir(DATA)) {
  if ($file =~ /passwd/) {
    ($host) = split /\./, $file, 2;
    print "Password file for $host found. Now processing...\n";
    open(FILE, "/usr/local/mysql/tmp_data/$file");
    while ($entry = <FILE>) {
      ($name, $passwd, $uid, $gid, $gcos, $home, $shell) =
split(/:/,$entry);
      if ($uid > 100) {
        $key1 = "$name"."-"."$host";
        my $test = $dbh->prepare("SELECT * FROM acct_db WHERE key1 = '$key1'
AND (uid <> '$uid' OR gid <> '$gid' OR gcos <> '$gcos' OR home <> '$home' OR
shell <> '$shell')");
        $test->execute ();
        $rows = $test->rows;
        if ($rows == 0) {
          $dbh->do("INSERT INTO acct_db
VALUES('$key1','$uid','$gid','$gcos','$home','$shell',NOW())")
or print "Error updating database: ", $dbh->errstr, "\n";(
          print "Adding $key1 to password database. \n";
        } elsif ($rows == 1) {
          print "$key1 already in database. Updating entry now.\n";
        } else {
          print "Error. \n";
        }
      }
    }
  }
}

        Thanks in advance for any help.

Scott Nipp
Phone: (214) 858-1289
E-mail: sn4265@sbc.com
Web: http:\\ldsa.sbcld.sbc.com



Relevant Pages

  • Get status of an user account in Tru64
    ... certain user account from within a script. ... front of the password entry in the passwd file, ... hands-on solution. ...
    (comp.unix.tru64)
  • Re: WORD doc info into FMP?
    ... it appears that each line of the entry follows the format ... number of any given type of field (Location, script, sets etc.) you might ... into a separate record in a database, and a separate related "database 2" ... Ten Nights in a Barroom (New York State Archives) ...
    (comp.databases.filemaker)
  • RE: Need some MySQL query help...
    ... attempting to run the script: ... passed to the database. ... passwd entry to the current database entry. ...
    (perl.dbi.users)
  • Re: How to make Apache (2.2.4) less greedy, or Sendmail less polite? [semi-solved]
    ... Then I make an entry in my /etc/hosts.allow file that denies access to all in my hosts.deny file. ... Firstly, I took some measures to figure out where the issues came from, and using Apache's "server-status" handler, I noticed the script that caused Apache to choke up, was a PHP script that shows entries of photographic events that I organise from time to time. ... I then wondered why, as this script never caused trouble before, and while checking the server status I did already notice that the "store comments" script was called very often. ... the machines that were used for this, and I will report them to the proper anti spam authorities, such that they will be blacklisted Internet wide. ...
    (freebsd-questions)
  • Re: Windows Explorer size reverting to 800x600
    ... I've pre-empted your reply and looking at your script I realise that the ... A similar entry exists in ... All of the folders are on a local drive. ... Const conBagMRUSize = _ ...
    (microsoft.public.windowsxp.general)