[ubuntu-my] simple bash scripting question

Umarzuki Mochlis umarzuki at gmail.com
Mon May 3 05:41:33 BST 2010


> create users according to folders in /home
> change ownership of each user to their own
>

here is my code for the last 2 lines (others can be done manually with tar
and ssh)
#!/bin/bash
## This for loop create a file with username and passwordformat
## needed by chpasswd
for i in /home/*
do
        user=$(echo $i | awk -F/ '{ print $3 }')
        echo $user:zaq12wsx >> userpass.txt
done

## This for loop creates a user, sets its predefined password
## which is zaq12wsx
for i in /home/*
do
        user=$(echo $i | awk -F/ '{ print $3 }')
        echo $user
        useradd $user; chown -R $user:$user $i; chpasswd < userpass.txt
done
## code end

and of course i'll save my behind by attaching a BSD license to this code

comments?

-- 
Regards,

Umarzuki Mochlis
http://debmal.my
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/ubuntu-my/attachments/20100503/6c19086b/attachment.htm 
-------------- next part --------------
Copyright 2010 Umarzuki Bin Mochlis Moktar. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, this list of
      conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice, this list
      of conditions and the following disclaimer in the documentation and/or other materials
      provided with the distribution.

THIS SOFTWARE IS PROVIDED BY UMARZUKI BIN MOCHLIS MOKTAR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Umarzuki Bin Mochlis Moktar.


More information about the Ubuntu-my mailing list