Created
January 14, 2015 20:08
-
-
Save hewittc/d1c5cded1f8215369b58 to your computer and use it in GitHub Desktop.
Quick hack for migrating passwords from netbsd5 to centos7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# | |
# Quick hack for migrating passwords from netbsd5 to rhel7. | |
# Christopher Hewitt 2014 | |
# | |
with open('master.passwd', 'r') as f: | |
print('#!/bin/sh') | |
for line in f: | |
locked = False | |
tokens = line.split(':') | |
if tokens[1] == '*************': | |
locked = True | |
user = tokens[0] | |
passwd = tokens[1].replace('$', '\$') | |
uid = tokens[2] | |
shell = '/bin/bash' | |
if 'tcsh' in tokens[9]: | |
shell = '/bin/tcsh' | |
elif 'csh' in tokens[9]: | |
shell = '/bin/csh' | |
elif 'zsh' in tokens[9]: | |
shell = '/bin/zsh' | |
if locked: | |
cmd = 'useradd -m -G users -u {} -s {} {}'.format(uid, shell, user) | |
else: | |
cmd = 'useradd -m -G users -u {} -s {} -p {} {}'.format(uid, shell, passwd, user) | |
print(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment