Create user add lines from partial passwd file

awk -F: '{print "useradd -u "$3,"-c \""$5"\"","-s "$7,$1}' passwd
Handy if you are installing a new server or recovering an old one and you have a passwd file with the accounts you want to add to the server. If you edit the file so that only the accounts that you want to add are left this line will spit out the correct useradd lines. The uid, gecos and shell will be preserved.
Sample Output
Input:
jsnuffy:x:600:600:Joe Snuffy:/home/jsnuffy:/bin/bash
hhandle:x:601:601:Harru Hoehandle:/home/hhandle:/bin/bash
ssimple:x:602:602:Sally Simple:/home/ssimple:/bin/bash

Output:
useradd -u 600 -c "Joe Snuffy" -s /bin/bash jsnuffy
useradd -u 601 -c "Harru Hoehandle" -s /bin/bash hhandle
useradd -u 602 -c "Sally Simple" -s /bin/bash ssimple

4
By: UnixSage
2010-06-06 11:54:35
awk

These Might Interest You


  • 0
    awk -F: '{print "echo "$1" | passwd --stdin "$1}' passwd
    UnixSage · 2011-09-12 16:58:12 1
  • The command copies a file from remote SSH host on port 8322 with bandwidth limit 100KB/sec; --progress shows a progress bar --partial turns partial download on; thus, you can resume the process if something goes wrong --bwlimit limits bandwidth by specified KB/sec --ipv4 selects IPv4 as preferred I find it useful to create the following alias: alias myscp='rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4' in ~/.bash_aliases, ~/.bash_profile, ~/.bash_login or ~/.bashrc where appropriate. Show Sample Output


    17
    rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4 user@domain.com:~/file.tgz .
    ruslan · 2011-02-10 14:25:22 2
  • Alternately for those without getent or only want to work on local users it's even easier: cut -d: -f1 /etc/passwd|xargs -n1 passwd -e Note that not all implementations of passwd support -e. On RH it would be passwd -x0 (?) and on Solaris it would be passwd -f.


    0
    getent passwd|cut -d: -f1|xargs -n1 passwd -e
    romulusnr · 2009-11-18 19:46:15 0
  • It can resume a failed secure copy ( usefull when you transfer big files like db dumps through vpn ) using rsync. It requires rsync installed in both hosts. rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file local -> remote or rsync --partial --progress --rsh=ssh $user@$host:$remote_file $destination_file remote -> local


    23
    rsync --partial --progress --rsh=ssh $file_source $user@$host:$destination_file
    dr_gogeta86 · 2009-04-01 13:13:14 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: