Skip to content

Instantly share code, notes, and snippets.

@hewittc
Created January 14, 2015 20:08
Show Gist options
  • Save hewittc/d1c5cded1f8215369b58 to your computer and use it in GitHub Desktop.
Save hewittc/d1c5cded1f8215369b58 to your computer and use it in GitHub Desktop.
Quick hack for migrating passwords from netbsd5 to centos7
#!/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