Script to convert /etc/passwd to useradd command line 

This is a very simple script to convert a /etc/passwd file to the associated useradd command line that creates the account. Useful for when your brain has turned off and you’re mid migration to a new system. Works with Linux and Solaris.

#!/usr/bin/perl -w
use strict;

while(<>) {
  chomp;
  my @a = split /:/;
  print 'useradd ';
  print '-d ' . $a[5] . ' ' if(defined $a[5]);
  print '-m -u ' . $a[2] . ' -g ' . $a[3] . ' ' ;
  print '-c "' . $a[4] . '"' if(length $a[4] > 0);
  if (!defined $a[6]) {
    $a[6] = "/usr/bin/false";
  }
  print ' -s ' . $a[6] . ' ' . $a[0] . "\n";
}