how to redirect stdout for htpasswd in script


Hi:

I've got an htpasswd authentication file that needs to be updated with the usernames and passwords from a database every day.

I've written a cron script that gets the values of the database and then calls htpasswd to update the authentication file.  The output from the cron job gets emailed to me every day - usually, just a lot of "Updating password for user **username**" lines.  I'd rather only get the cron email if there's a problem - a missing password or something.

My first thought was to just redirect stdout to /dev/null in the crontab, like this:

0 19 * * * /usr/bin/perl /home/user/bin/scripname.pl >/dev/null

but it doesn't seem to work.   I still get the output from the htpasswd command emailed to me.  Is it getting printed on stderr?  if so, I don't want to redirect stderr to /dev/null because then I'll miss any errors that occur.

Am I doing anything wrong?  Anyone had any experience like this?

-Charlie
gothamwwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jlevieCommented:
> Is it getting printed on stderr?

Yes.

Since you are using perl to update the auth file why not directly manuipulate the file with the Perl script. It is pretty easy to generate the encrypted password within Perl. For DES encrypted passwords you can use:

sub descrypt()
{
  my($pw) = @_;
  $salts  = "0123456789";
  $salts .= "abcdefghijklmnopqrstuvwxyz";
  $salts .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $nsalts = length($salts);
                                                                                               
  $i = int(rand $nsalts);
  $ii = int(rand $nsalts);
  $salt = substr($salts, $i, 1).substr($salts, $ii, 1);
  $epw = crypt($pw, $salt);
  return($epw);
}

which is used like:

$epw = descrypt($passwd);

$passwd holds the plain text password and $epw the DES encrypted result.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gothamwwAuthor Commented:

so, the authentication file that htpasswd generates is just an ordinary text file that can be edited by any means, as long as the password is "DES" encrypted and each record is in the format:

username:DESencpasswd
0
jlevieCommented:
Yep, assuming that you are using the flat file rather than a DB. If that's the case you can use any text editor to examine the auth file to see what it looks like. On a Linux system the encrypted passwords in the auth file can be encrypted with DES or MD5. The format of the encrypted password will auto-select the correct encryption method. See 'man 3 crypt' for details.
0
gothamwwAuthor Commented:
Thanks a lot jlevie
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.