How to mount FTP resources with fstab when connection is available?
As your goal is "to syncronize a local folder with the ftp folder with a crontab rsync", I suggest you to write a small script that mounts the FTP, rsync, unmount FTP. Then run this script from crontab.
It should go something like this:
#!/bin/bash
curlftpfs user:pwd@myhost:port/folder/ /mnt/mymountfolder
#might need sleep 1 here
rsync -a /mnt/mymountfolder /local/folder
fusermount -uz /mnt/mymountfolder
Make sure you chmod +x on the script.
crontab -e
#m h d M wd
0 * * * * /usr/local/bin/backup-script
Also, if you really want the FTP folder mounted all the time, you could make a script that mounts/unmounts your drive. If you also add it to fstab, you could manually mount the drive.
fstab:
curlftpfs#user:pwd@myhost:port/folder/ /mnt/mymountfolder fuse noauto,user,uid=1000,gid=1000,umask=0022 0 0
network-mount.sh:
#!/bin/bash
folder=/media/ftp
# check if host is alive
ping=`/usr/bin/fping -q host.dyn.org`
if [ $? == 0 ]; then
# check if folder is mounted
mountpoint $folder > /dev/null
if [ $? != 0 ]
# mount, timeout in case something goes wrong
then timeout 10s mount $folder
fi
else
mountpoint $folder > /dev/null
if [ $? = 0 ]
#unmount lazy (network down)
then umount -l $folder
fi
fi
Add this to crontab (crontab -e):
* * * * * /usr/local/bin/network-mount.sh
Also watch out for your rsync not completing before the next is run. This could be done automatically(check if rsync running), or based upon how much data that need to be in sync(amount of time rsync takes, worst case scenario).
Assuming you don't run rsync for anything else, checking if it's running could be done like this:
pgrep rsync
if [ $? == 0 ]; then
# rsync running
exit
else
# rsync not running
#do stuff
fi