LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-25-2008, 09:56 PM   #1
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Rep: Reputation: 31
A simple Bash file for importing SAMBA users from a file


Hi

I need a a bash file that will import samba users and also create a default password.

I currently have a CSV file like this

Code:
username1, password1
username2, password2
username3, password3
.
.
.
I need a script that will take each username and password and execute something like the following command.

Code:
smbldap-adduser username1 -P password1
This should loop through each line from the CSV file in turn and execute this command automatically for me.

Any ideas?
 
Old 12-26-2008, 11:52 AM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by jax8 View Post
Hi

I need a a bash file that will import samba ...<SNIP>...

This should loop through each line from the CSV file in turn and execute this command automatically for me.

Any ideas?
This is quick and dirty with no error checking. There are far better ways of doing this, but this will suffice or at least give you a place to start from.

Code:
#!/bin/bash
CSVFILE=/home/bob/filename.csv
SLAU=`which smbldap-adduser`
for i in `cat $CSVFILE|sed 's/, /,/g'`; do
        UN=`echo $i | cut -f1 -d','`
        PW=`echo $i | cut -f2 -d','`
        echo $SLAU $UN -P $PW
done
I left the echo in there so you could give it a test run with no danger, take the echo out and it will execute what it displayed during the test runs for real.
 
Old 01-04-2009, 10:13 PM   #3
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Original Poster
Rep: Reputation: 31
Thanks for that rweaver - worked great

I gave you the wrong command though. For anyone else using this script use smbldap-useradd not smbldap-adduser.

cheers
 
Old 01-05-2009, 08:06 AM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by jax8 View Post
Thanks for that rweaver - worked great

I gave you the wrong command though. For anyone else using this script use smbldap-useradd not smbldap-adduser.

cheers
Glad it worked out for you, we had a good discussion about bulk user addition tools in this thread too you might find some items of interest.

http://www.linuxquestions.org/questi...script-693777/
 
Old 01-31-2009, 04:51 AM   #5
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Rep: Reputation: 1
not working
 
Old 02-01-2009, 12:00 AM   #6
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by prakash0106 View Post
not working
Not a useful reply.
 
Old 02-01-2009, 11:16 PM   #7
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Original Poster
Rep: Reputation: 31
Here is my file

Code:
#!/bin/bash
CSVFILE=/home/acep/Desktop/Import_Export/smbUsers.csv
SLAU=`which smbldap-useradd`
for i in `cat $CSVFILE|sed 's/, /,/g'`; do
        UN=`echo $i | cut -f1 -d','`
        #PW=`echo $i | cut -f2 -d','`
        $SLAU -a -m $UN
done
1. Change CSVFILE=/home/acep/Desktop/Import_Export/smbUsers.csv to the location of your csv file

Should work OK
 
Old 02-02-2009, 02:10 PM   #8
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by jax8 View Post
Here is my file

Code:
#!/bin/bash
CSVFILE=/home/acep/Desktop/Import_Export/smbUsers.csv
SLAU=`which smbldap-useradd`
for i in `cat $CSVFILE|sed 's/, /,/g'`; do
        UN=`echo $i | cut -f1 -d','`
        #PW=`echo $i | cut -f2 -d','`
        $SLAU -a -m $UN
done
1. Change CSVFILE=/home/acep/Desktop/Import_Export/smbUsers.csv to the location of your csv file

Should work OK
Try putting an echo in front of the $SLAU

eg:
Code:
echo $SLAU -a -m $UN
Should give you a bit of diagnostic information on what is occurring... my initial guess would be you don't have 'which' or you don't have smbldap-useradd in your path.

Last edited by rweaver; 02-02-2009 at 02:11 PM.
 
Old 02-02-2009, 11:44 PM   #9
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Rep: Reputation: 1
[root@fs test]# ls
slua slup.csv smbldap-conf test1 useradd_smbpwd


[root@fs test]# cat slup.csv
sri, sri


[root@fs test]# cat slua
#!/bin/bash
CSVFILE=/root/test/slup.csv
SLAU=`which smbldap-useradd`
for i in `cat $CSVFILE|sed 's/, /, /g'`; do
UN=`echo $i | cut -f1 -d','`
#PW=`echo $i | cut -f2 -d','`
echo $SLAU -a -m $UN
done


[root@fs test]# ./slua
/usr/sbin/smbldap-useradd -a -m sri
/usr/sbin/smbldap-useradd -a -m sri


[root@fs test]# pdbedit -L sri
Username not found!


[root@fs test]#


any correction in this details?
 
Old 02-03-2009, 01:15 PM   #10
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by prakash0106 View Post
<SNIP>


any correction in this details?
Code:
for i in `cat $CSVFILE|sed 's/, /,/g'`; do
Try manually using the command line it is echoing to the screen to add a user and see what happens.
 
Old 02-07-2009, 06:05 AM   #11
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Original Poster
Rep: Reputation: 31
That looks correct prakash0106.

Now remove the "echo" and the "#" in front of the PW command and execute the command for real.
 
Old 02-09-2009, 09:12 AM   #12
prakash0106
LQ Newbie
 
Registered: Jan 2009
Posts: 15

Rep: Reputation: 1
hi,

thanks yaar, now its working.

1 small question i need smbldap-useradd with -g "Domain Users" -G (group name)(user name)

please give ur guide

sorry 2 disturb u........

prakash.m
 
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
importing users from active directory into openldap and get working with samba kcorupe Linux - Server 2 11-18-2009 10:26 AM
Simple parse of html file using bash ericcarlson Linux - Software 2 05-07-2008 09:44 AM
allow users to mount a samba file share only amon Linux - Software 3 04-05-2006 02:48 PM
cannot delete any file of other users (samba question) eduac Linux - Software 2 02-07-2006 03:11 AM
samba file share with windows users Peds222 Linux - Software 6 08-22-2003 12:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration