I am trying to append a variable from an adduser script to a line in a
config file (for samba).
Can someone assist me here?
The function is in BOLD below: *createNewSambaAllow()*
*
*
It's not working to put the new line in the smb.conf file?
Cry! Beg! Plead!
Note: This is a assuming I already have a user named "unique" in my
smb.conf line.
#####################################start
script#######################################3
#!/bin/bash
# Add shell and samba user.
_now=$(date +"%m_%d_%Y")
basedir=/home
usershell=/bin/bash
## Declare all the functions first
## function to check if user already exists on system
ifUserExits(){
grep $1 /etc/passwd > /dev/null
[ $? -eq 0 ] && return $TRUE || return $FALSE
}
## function to create the user with default shell and home directory passed
from below
createNewUser(){
if /usr/sbin/useradd "$@"
then echo "User $6 Added"
fi
}
## function to set the user password
createPassword(){
if echo -e "$1\n$1\n" | echo $1:$2 |chpasswd
then echo "Password Created for User $2"
fi
}
## function to setup samba user
createNewSambaUser(){
if (echo $1; echo $1) | /usr/bin/smbpasswd -as $2
then echo "Samba Account for User $2 Added"
fi
}
*#####This is the part I have issues with:*
*
*
*## function to add user to the Samba config and restart daemon*
*createNewSambaAllow(){*
* # Copy to backup the config:*
* cp /etc/samba/smb.conf /etc/samba/smb.conf-$_now*
* # stuff the line we need to append to into a variable called
$oldline*
* # this is supposed to look like this "valid users = unique thing1
thing2 thing3 alice"*
* oldline = grep unique /etc/samba/smb.conf*
* # delete the old line in the smb.conf*
* sed '/unique/d' /etc/samba/smb.conf >>/etc/samba/smb.conf*
* # dump the old line and the new user into the bottom of smb.conf*
* echo $oldline && echo $username >> /etc/samba/smb.conf*
* # restart samba*
* /etc/init.d/samba restart*
* echo "Samba Config Added and Daemon restarted"*
*}*
### This is just for your info #####
## make sure root is running script
if [ $(id -u) -ne 0 ]
then
echo "You must be root or use sudo to run this script!"
exit 2
fi
## get username from input
read -p "Enter username : " username
## if user doesn't exist, add user
if ( ! ifUserExits $username )
then
## get password from input
read -p "Enter password : " password
createNewUser -m -b $basedir -s $usershell $username
createPassword $password $username
createNewSambaUser $password $username
createNewSambaAllow $username
else
## oops, username already being used
echo "Username \"$username\" already exists"
exit 3
fi
# End Bash Example
--
Anyone?
(503) 754-4452 Android
(623) 239-3392 Skype
(623) 688-3392 Google Voice
**
it-clowns.com <
http://it-clowns.com/c/>
Chief Clown
---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss