Life of a Blogger

Bleuken.i.ph is my first ever blog and give me opportunity to post different topics that can help other people to make money online and go through cyberspace. This started at Roxas City, Capiz, Philippines. This blog is intend to post different advice on programming, web design, search engine optimization (SEO Challenges, SEO Contests), information about viruses and how to remove it, making money online and contain some of my experiences online.

If you wish to suggest or send feedbacks, you can contact me at fbaguyo[at]hotmail[dot]com

Linux Script that Adds New Samba Users

May 31, 2007

I did have a hard time looking for information regarding linux scripts that adds new samba users (many users) so I decided to log the script I made to add new samba users. I tried to use the method that some sites suggested that copies the /etc/passwd to /etc/samba/smbpasswd via cat < /etc/passwd | makesmbpasswd.sh > /etc/samba/smbpasswd, but this does not work. By the way, I'm using Samba 3.025d under OpenSuse 10.2

So i tried to figure it out by conducting a trial and error 'experiments' :) and luckily I did it. The things I've done are the following:

First I add 1000 UNIX users using the following scripts (unixusers.sh)

#—————————————————————————————————–

# Script: unixusers.sh - use for creating 1000 users by Felix 

#I declare 100 unique passwords in an array

declare apasswords[100]
apasswords[0]="password1"
apasswords[1]="pasword2"
apasswords[1]="… and so on… up to 100 unique passwords'

n=0
for ((i=1;i<=1000;i++))
do
    echo "user$i = ${apasswords[n]}" >> mypasswords.txt
    cuser="user$i"
    cpassword="${apasswords[n]}"
    echo "Wait creating user $cuser = $cpassword, please wait…"
    useradd $cuser -p $cpassword
    n=`expr $n + 1`
    if test $n -gt 100

    then
        n=0
    fi
done
#—————— unixusers.sh ends here ———————————-

The unixusers.sh script will create 1000 UNIX users with passwords.User ids and passwords are saved inside a text file name: mypasswords.txt, if in case you want to have print-out of the users and passwords.

Now, the following is the script that adds the 1000 UNIX users to SAMBA (/etc/samba/smbpasswd) 

#—————————————————————————————————–

# Script: sambausers.sh - use for creating 1000 SMB users by Felix

 #I declare 100 unique passwords in an array the same as the passwords on unixusers.sh

declare apasswords[100]
apasswords[0]="password1"
apasswords[1]="pasword2"
apasswords[1]="… and so on… up to 100 unique passwords'
 

n=0
for ((i=1;i<=1000;i++))
do
    rm temp.txt
    echo "${apasswords[n]}" >> temp.txt
    echo "${apasswords[n]}" >> temp.txt
    cuser="user$i"
    cpassword="${apasswords[n]}"
    echo "Wait creating user $cuser = $cpassword, please wait…"   
    smbpasswd -a $cuser -s < temp.txt
    n=`expr $n + 1`

    if test $n -gt 100   

    then
        n=0
    fi
done
 #—————— sambausers.sh ends here ———————————-

That's all folks! A script that adds new samba users (for SAMBA 3.025d in openSUSE 10.2).

Posted by bleuken at 3:38 pm | permalink | View this entry

Search

Business Software

For online storing of receipts, organizing and managing your expenses, use an Expense Management Software with their system to help you quickly prepare your expense report, what you could ask for?

Sponsored Links

    

Blog Directories

Recent Viewers