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
Printable View
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
.htpasswd is just a text file, you can edit it in notepad or directly on the server with a text editor like vi. The other way you can edit it is through your billing company's script.
cheers,
Luke
Hehe, that's too easy
I did programm something myself to add users
[...]
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() {
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);
not sure why it didn't come through, but the "while" line should be:
Code:
while() {
ok...it's not liking that..let's try this:
while(<F>) {
cool, thanks hagan :D
now I can complete my user management :D
Quote:
Originally Posted by DEVELISH
wow..i'm surprised that it actually worked!!
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
hehehe....ok!