1

I'm having a bit of trouble with a shell script. It's something so stupid I'm almost ashamed to ask, but I can't figure it out.

This is the script:

#!/bin/bash

MAGAZINE="
    192.168.49.3
    192.168.49.5
"

SYNC="192.168.250.40"

#mount //$SYNC/PozeSync /home/alex/pozesync -o user=magazin,password=,sec=ntlm &&

for magazin in $MAGAZINE; do
    if ping -c 1 -t 1 $magazin &> /dev/null
        then
            echo "$magazin is down"
        else
            echo "$magazin is up"
            mount -t cifs //$magazin/PozeUpload /home/alex/mounts -o user=Administrator,password= &&
            rsync --bwlimit=1000 -r /home/alex/mounts/* &&
            rm -rf /home/alex/mounts/* &&
            umount /home/alex/mounts &&
            echo "$magazin done" >> sync.log
    fi
done

#umount /home/alex/pozesync

As you can see, there are two lines commented. If I uncomment them, the script stops working properly. It doesn't mount the pozesync folder and then throws some samba errors trying to load the folders in the loop.

If I run the mount/umount commands without the loop, it works fine. If I run the loop without the mount/umount commands, it works fine.

Run them together however and...

192.168.49.3 is up
rsync: link_stat "/home/alex/mounts/*" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

What am I doing wrong?

6
  • Why put && at the end of almost every line? There's nothing on the line afterwards to run if it's sucessful
    – Xen2050
    Feb 17, 2015 at 13:06
  • Where does the mount command get the password from?
    – Paul
    Feb 17, 2015 at 13:07
  • @Xen2050 thought it would be good to run the other commands only after the previous ones finish correctly. Thought that was a good way to do it.
    – Faryus
    Feb 17, 2015 at 13:18
  • @Paul I removed the passwords from the code, but they are supplied in the script.
    – Faryus
    Feb 17, 2015 at 13:19
  • I wasn't sure if putting && at the end of a line would "chain" it to the next command, without being on the same line or a `` or something to tie them together... but it does work as you expected/described. Interesting, +1 just for learning that
    – Xen2050
    Feb 17, 2015 at 14:14

1 Answer 1

0

This was my mistake:

rsync --bwlimit=1000 -r /home/alex/mounts/* &&

should actually be

rsync --bwlimit=1000 -r /home/alex/mounts/ &&

Cheers!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .