sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #47683
bash script og expect
Hej.
Jeg har en SUSE 7.3 box som fil server. Jeg har derfor lavet et lille bash
script til at oprette en "linux" konto, derefter opretter det en samba konto
med samme infos. Og til sidst flytter det brugerens gamle hjemme katalog fra
en novell server. For at slippe for at skulle taste passwords ind flere
gange ville jeg gerne bruge expect, men jeg kan ikke rigtig få det til at
virke. Mit script er nedenfor. Det virkede uden expect, men så skulle jeg jo
taste password in et par gange.
/Lasse
*******
#!/bin/bash
#!/usr/local/expect -f
NOVFOLDER=/home/Novell/DCMR1/vol1/DATA/brugere
USERFOLDER=/home/users
#get info on the user
echo
echo -n "Type username: "
read USERNAME
echo -n "Type password: "
read PASSWORD
echo -n "Type default group: "
read DGROUP
echo -n "Type additional groups (comma seperated): "
read AGROUP
echo -n "Type Novell username, CASE IMPORTENT: "
read NOVELLUSER
clear
#Check if info is correct, else do brutal exit
echo
echo "The info you entered was:"
echo "Username: $USERNAME"
echo "Password: $PASSWORD"
echo "Default group: $DGROUP"
echo "Additional groups: $AGROUP"
echo
echo "Novell files will be moved from $NOVFOLDER/$NOVELLUSER"
echo
echo
echo -n "Is the information correct (y=YES,n=NO)?: "
read ABORT
echo
if [ "$ABORT" = "n" ]; then
echo "NO?? to bad - exiting now!"
exit 1
else
echo "Now creating the user..."
echo "sleeping for 3 seconds"
echo "final WARNING."
sleep 3
echo "Oki - you asked for it, here it comes"
fi
# create UNIX user
useradd -g $DGROUP -G $AGROUP -d $USERFOLDER/$USERNAME $USERNAME
echo "User now created"
echo
#echo "Now setting UNIX password"
passwd $USERNAME
expect "password:"
send $PASSWORD\r
expect "password:"
send $PASSWORD\r
echo "UNIX password changed to $PASSWORD"
#now create samba entry
echo
echo "creating SAMBA entry
smbpasswd -a $USERNAME
expect "password:"
send $PASSWORD\r
expect "password:"
send $PASSWORD\r
echo samba entry added
#Move userfiles from NOVELL folder.
echo
echo "Now moving files from NOVELL, this may take some time"
cp -R $NOVFOLDER/$NOVELLUSER/* $USERFOLDER/$USERNAME/
echo "Old userfiles moved"
#Now setting permissions
echo
echo "Setting file permissions on moved files"
chown -R $USERNAME:$DGROUP $USERFOLDER/$USERNAME
exit 0
Follow ups
-
.forward
From: Dan "DaddySoon" Mortensen, 2002-02-11