Hoi Allemaal,We hebben een werkend script:
Ten eerste het expect script (hiervoor heb ik expect geinstalleerd)Expect staat in /usr/bin/expect -fScript 1 scriptnaam setpasswd:#!/usr/bin/expect -f
# -----------------------------------------------
# Copyright (c) 2006 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit
http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# display usage
if {$argc!=2} {
send_user "usage: $argv0 username password \n"
exit
}
# script must be run by root user
set whoami [exec id -u]
if {$whoami!=0} {
send_user "You must be a root user to run this script\n"
exit
}
#
set timeout -1
match_max 100000
# store password
set password [lindex $argv 1]
# username
set user [lindex $argv 0]
# opem shell
spawn $env(SHELL)
# send passwd command
send -- "passwd $user\r"
expect "assword:"
send "$password\r"
expect "assword:"
send "$password\r"
send "\r"
send "exit\r"
expect eof
Script 2 scriptnaam passwdscript:
(Beide scripts staan in /home)
Start Script 2:#!/bin/bash
#
# Ensure that root is running the script.
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/home/names.txt"
cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
useradd ${USER}
echo Added user ${USER}
/home/setpasswd ${USER} ${SMBPASS}
smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
(echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}
echo -e "${USER} = ${USER}" >> /etc/samba/smbusers
done
Extra Info:Met het script kun je meerdere users en samba users in een keer aanmaken die is zeer handig als je ubuntu als server gebruikt en b.v. 100 users aan moet maken.
Het script is voor ubuntu geschreven.
Als eerste maak je een textfile aan in home/names.txt
De inhoud van deze file is alsvolgt:
piet 1234
cees 5678
In rij 1 staat de username.
In rij 2 staat het password.
Wat gebeurd er:
Als je het script start (passwdscript) maakt hij een account aan + een samba account.
Met dank aan allen die hierbij geholpen hebben.