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?
&&
at the end of almost every line? There's nothing on the line afterwards to run if it's sucessfulmount
command get the password from?&&
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