Hi,
i need to delete a user from the .htpassword file - no, not by hand but by a programm (shell script or php or something)
my htpasswd command does not support the "-D" for deleting a user.
anybody have an idea?
THANKS ;D
DEVELISH
Hi,
i need to delete a user from the .htpassword file - no, not by hand but by a programm (shell script or php or something)
my htpasswd command does not support the "-D" for deleting a user.
anybody have an idea?
THANKS ;D
DEVELISH
Hehe, that's too easy
I did programm something myself to add users
<?php
[...]
exec ('htpasswd and more code to add user');
[...]
?>
now I need to delete one single user from the .htpasswd file
the command to do this is "htpasswd -D .htpasswd username" but my htpasswd command does not support the -D option
I'd like to do something like this
so I can call the script withCode:#!/bin/bash users=`cat /path/to/.htpasswd` $searchFor =`cat /path/to/.htpasswd | grep $1` for Name in $users do #if $name is not the username to be deleted write to a tmp file if [$Name != $searchFor] write $name to /path/to/htpasswd.tmp fi done mv /path/to/htpasswd.tmp /path/to/.htpasswd done
$ ./script.sh username
Develish ;D
i wrote a real quick simple perl script that will do what you're looking for. use this at your own risk, as i didn't have the time to debug/test it.
you can run it via the command line: perl scriptname.pl username
Code:#!/usr/bin/perl $password_file = '/path/to/.htpasswd'; $username_to_delete = $ARGV[0]; open(F,"$password_file") || die "$!"; while(<F>) { chomp; ($u,$p) = split /\:/,$_; push (@logins,$_) unless ($u eq $username_to_delete); } close(F); open(F,">$password_file") || die "$!"; foreach (@logins) { print F "$_\n"; } close(F);
cool, thanks hagan
now I can complete my user management
Oh, that I don't know yet,
I copied the code but have not tested it yet - will do it within the next couple of hours ;D
DEVELISH
Bookmarks