I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server.
My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using getfacl/setfacl.
I tried to run my script by using ./man_fs2-copy.sh:
./man_fs2-copy.sh: line 28: syntax error near unexpected token `done'
./man_fs2-copy.sh: line 28: `done cat /tmp/error.log | mail -s "Here is the log for $share" $email && rm /tmp/error.log'
I also tried to run the script like this, sh man_fs2-copy.sh and I get the following error,
man_fs2-copy.sh: 22: Syntax error: Bad for loop variable
#!/bin/bash
#
#
# This script will create the necessary directories, mount man_fs2 (c$, e$, f$ and g$)
# then read from directorylist.txt and start copying the directory's
#
#
echo "What is your email address?"
read email
#
#
mkdir -p /servers/backups /servers/man_fs2 /servers/man_fs2-logs
mkdir -p /home/man_fs2/c /home/man_fs2/e /home/man_fs2/f /home/man_fs2/g
chmod -R 777 /servers
cd /servers
#
# Mount man_fs2
mount //man_fs2/c$ /home/man_fs2/c -oacl,username=administrator@domain.local,password=*****
mount //man_fs2/e$ /home/man_fs2/e -oacl,username=administrator@domain.local,password=*****
mount //man_fs2/f$ /home/man_fs2/f -oacl,username=administrator@domain.local,password=*****
mount //man_fs2/g$ /home/man_fs2/g -oacl,username=administrator@domain.local,password=*****
#
#
for (( c=1; c<=2; c++ ))
do
cat directorylist.txt | while read source dest share
cp -Rv "$source" "$dest" 2> /tmp/error.log
echo "Setting ACLs from $source to $dest:"
getfacl -R "$source" | setfacl -R --set-file=- "$dest"
done
cat /tmp/error.log | mail -s "Here is the log for $share" $email && rm /tmp/error.log
echo "Pass # $c"
if [ ! -d "$src" ];
then
cp -aR $src $dest
getfacl -R $src | setfacl -R --set-file=- $dest
else
cp -uR $src $dest
getfacl -R $src | setfacl -R --set-file=- $dest
fi
done
echo "Unmount all drives"
umount /home/man_fs2/c
umount /home/man_fs2/e
umount /home/man_fs2/f
umount /home/man_fs2/g
exit