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
myhost
. You can add a IP <=> name mapping in/etc/hosts
, see if it helps. Otherwise change myhost to FQDN or IP address. – Terry Wang Jul 17 '13 at 00:29myhost
? For example, do I ping and see if you can reach it. If not, you may have to do a IP - Hostname mapping in/etc/hosts
to make it work. – Terry Wang Jul 19 '13 at 01:39Autofs is quite difficult to configure, and I'm not sure it would solve the issue, as I'm investigating and I found my wireless is available only after the login. Both fstab and autofs solutions are near to be abandoned...:(
– jasmines Jul 19 '13 at 05:03sudo mount -a
)? If not, can you try another server, e.g. ftp.mozilla.org? Also, I'm not sure if it's possible to add the/folder/
-part in fstab. – Clausi Jul 19 '13 at 09:30mount
ftp on android phone, do some stuff andumount
should work. Wondering if your experience over the years will confirm strategy? – WinEunuuchs2Unix Oct 06 '19 at 01:37