Bash script - im missing something and cant's figure out what


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script - im missing something and cant's figure out what
# 1  
Old 05-15-2011
Bash script - im missing something and cant's figure out what

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:
Code:
./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,
Code:
man_fs2-copy.sh: 22: Syntax error: Bad for loop variable




Code:
#!/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

# 2  
Old 05-15-2011
It looks to me like you're missing a do at the start of the while:

Code:
for (( c=1; c<=2; c++ ))
do
    cat directorylist.txt | while read source dest share
    do
        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

I've changed your indention to be what I think you intended as far as loop structure is concerned. Bash didn't complain about a bad loop var when I changed and ran the script through -n syntax checking.
This User Gave Thanks to agama For This Post:
# 3  
Old 05-15-2011
Thanks alot for your help. That fixed those errors

---------- Post updated at 10:10 PM ---------- Previous update was at 08:57 PM ----------

I fixed the issue that I was having but im now having trouble with another part of my script, specifically when I try to do the getfacl/setfacl.

Setting ACLs from "/home/man_fs2/e/couplings*" to "/servers/man_fs2/couplings":
getfacl: "/home/man_fs2/e/couplings*": No such file or directory
Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ...
# 4  
Old 05-15-2011
It's difficult to say for sure, but your problem might be the quotes:
Code:
getfacl -R "$source" | setfacl -R --set-file=- "$dest"

I think they should go....

By quoting the variable $source, you don't allow for any file glob expansion. Thus /home/man_fs2/e/couplings* does not expand and the file with the splat (*) at the end does not exist. This assumes that there are multiple files in /home/man_fs2/e/ that start with couplings.

If couplings is a directory, and you wish to have all files in the directory processed, then in addition to dropping the quotes, you'll need to add a slant:
Code:
/home/man_fs2/e/couplings/*

This is speculation as I don't really know what your source directory structure looks like. With luck this is it, and if not I hope it helps get you going again.
This User Gave Thanks to agama For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add missing date and time in a bash script?

Hi Again, I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file. INPUT 2016-01-13 01:33 10 2016-01-13 01:31 10 2016-01-13 01:30 10 2016-01-13 01:29 10 2016-01-13 01:28 10 2016-01-13 01:27 10 2016-01-13 01:26 10 2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies

2. Shell Programming and Scripting

Help with change significant figure to normal figure command

Hi, Below is my input file: Long list of significant figure 1.757E-4 7.51E-3 5.634E-5 . . . Desired output file: 0.0001757 0.00751 0.00005634 . . . (10 Replies)
Discussion started by: perl_beginner
10 Replies

3. UNIX for Dummies Questions & Answers

[Solved] ksh script - can't figure out what's wrong

Hi! (I guess this could of gone into the scripting forum, but Unix for Dummies seemed more appropriate. Please note that I am not in school, so Homework doesn't seem appropriate either. You guys can let me know if you think otherwise.) I am following an exercise in a book on ksh scripting which... (2 Replies)
Discussion started by: sudon't
2 Replies

4. Shell Programming and Scripting

cant figure out the error in this script (adding numbers in a string) using ubantu shell

hii please help me this is the script num=$1 sum=0 while do x=`expr $num % 10` sum=`expr $sum + $x` num=`expr $num / 10` done echo "Summation is $sum" it is giving error pratyush@ubuntu:~$ sh shell.sh 123 shell.sh: 11: 123: not found Summation is 0 (3 Replies)
Discussion started by: Pratyush Sakhle
3 Replies

5. Shell Programming and Scripting

Anybody here can help me to figure thie perl script out?

Gey guys, I'm a new learner of perl. Now I encountered a problem when I tried to get the output below from the input file. Input: 5'h1f, 16'h8210 write, 5'h10, 16'h0000 write, 5'h11, 16'h0000 5'h1f, 16'hffd0 write, 5'h1e, 16'h0000 5'h1f, 16'h8310 read, 5'h10, rd_data 5'h1f,... (3 Replies)
Discussion started by: sunbaby
3 Replies

6. Shell Programming and Scripting

Find missing string with bash

If I have a file called file A with a list of filenames. How do I find all the filenames in file A that aren't contained in file B? I want to use bash scripting. (2 Replies)
Discussion started by: locoroco
2 Replies

7. Shell Programming and Scripting

Spent all day trying to figure this script out...

Before I begin with the question, I just want to point out that I just started learning unix in the middle of last week, so my code (and knowledge of how unix operates) is weak sauce. I took my best stab at this question but it's just not working. Assignment: Create a script named... (1 Reply)
Discussion started by: ashkali1
1 Replies

8. Shell Programming and Scripting

Bash script error: missing destination file name operand.

Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup the binary logs. It runs in the cron every 2 hours or so (although I can't get my script to run properly atm, which is why... (1 Reply)
Discussion started by: cganly
1 Replies

9. Shell Programming and Scripting

Bash uniq/ diff/ and other I cant figure it out

First off thank you for any help. Here is the problem. I have two text files that fit the same format. The first I created using an ls -d command and then with the help of the forums ran awk resulting in the fallowing output. W00CHZ0103345-I1CZ44 W00E6S1016722-I01JW159... (8 Replies)
Discussion started by: Movomito
8 Replies

10. Solaris

Missing init files for zsh and bash

I change my default shell to zsh but can't find the init files, .zshrc and .zlogin from /export/home and /home. The other shells init files are there:.cshrc, .profile and .login. Am I suppose to use these as templates? Also, bash_history is there but not zsh_history although zsh do keep a... (2 Replies)
Discussion started by: maag
2 Replies
Login or Register to Ask a Question