#!/bin/sh # aap - aljex account propogation # # Similar to the "ap" command from SCO # Reads /etc/passwd and /etc/shadow from a SCO box, then outputs # the appropriate "useradd" commands to recreate the same users on linux. # Pipe the output into sh to actually run the commands. # # TODO: userdefs, gecos, sanity checking, unlimited names list, run on sco # # 20070106 brian@aljex.com self=${0##*/} usage () { echo "$self - aljex account propogation" echo echo "usage: $self passwdfile shadowfile [names...] [|sh]" echo echo "passwdfile - Copy of /etc/passwd from a SCO or Linux box." echo "shadowfile - Copy of /etc/shadow from a SCO or Linux box." echo "names... - Optional list of usernames to process." echo "|sh - For safety, $self just prints out useradd commands." echo " To actually run the commands, pipe the output into sh," echo " which just means add \"|sh\" to the end" echo echo "If no names are specified, then all the names in passwdfile are used." echo "UID's under 200 are ignored. (root, bin, sys, lp, etc...)" echo "Accounts that already exist are not overwritten." echo "Source passwd & shadow files can come from SCO or Linux" echo "Local machine where $self is run must be Linux" echo "To move users from SCO to SCO, use \"ap\" instead of \"$self\"." echo echo "So, in most cases you just copy the passwd & shadow files" echo "from the source box to a local temp directory, then run" echo "\"$self passwd shadow\" and then \"$self passwd shadow |sh\"" exit 1 } [ $# -lt 2 ] && usage PASSWDFILE=$1 ; shift SHADOWFILE=$1 ; shift [ $# -gt 0 ] && { NAMES=$@ } || { NAMES=`cut -d: -f1 < $PASSWDFILE` } for i in $NAMES ; do awk -F: '($1==I){printf $1":"$2":"}' I=$i $SHADOWFILE awk -F: '($1==I){printf $3}' I=$i $PASSWDFILE echo done |awk -F: '($3>=200){print("useradd -m -p \""$2"\" -u "$3" "$1)}'