/var/samba_test/userpasswd 的格式为

user:password

user1:password1

user2:password2


root@ubuntu:/var/samba_test# cat smbpasswdstart.sh

#!/bin/sh

for LINE in `cat /var/samba_test/userpasswd`

do

N=`echo $LINE | awk -F ':' '{print $1}'`

P=`echo $LINE | awk -F ':' '{print $2}'`

/var/samba_test/smbpasswd.sh $N $P

done


root@ubuntu:/var/samba_test# cat smbpasswd.sh

#!/usr/bin/expect -f

set n [lindex $argv 0]

set p [lindex $argv 1]

spawn smbpasswd -a $n

set timeout 1

expect '*password:'

set timeout 1

send $p\n

expect '*password:'

set timeout 1

send $p\n

expect eof


通过运行smbpasswdstart.sh来实现批量添加用户,关键是使用了expect工具