Skip to content

Instantly share code, notes, and snippets.

@tsuyo
Created October 4, 2021 12:06
Show Gist options
  • Save tsuyo/96fee3b86581014f82558a1871d74f9f to your computer and use it in GitHub Desktop.
Save tsuyo/96fee3b86581014f82558a1871d74f9f to your computer and use it in GitHub Desktop.
htpasswd_batch.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from subprocess import Popen,PIPE
dav_svn_passwd = '/etc/apache2/dav_svn.passwd'
if len(sys.argv) < 2:
print "Usage:", sys.argv[0], "<passwd.txt>"
sys.exit(0)
file = open(sys.argv[1])
for entry in file.readlines():
(user, passwd) = entry.strip().split('/')[1:3]
proc = Popen(["htpasswd", "-b", "-m", dav_svn_passwd, user, passwd], stdout=PIPE, stderr=PIPE)
print "add or change", user
stdout, stderr = proc.communicate()
print stdout
print stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment