Monday, November 15, 2010

upload to a ftp server a file on samba system on a dayly base

I had today the need to transfer a pdf (named on a date base) which I retrieve from a samba server every day from my intranet which is not accessible from outside to a more easily accessible webserver:

Problems: 
  • mount the samba server CLI (fstab)
  • dont be asked for a password from the ftpserver (I will use the .netrc)
 
1st of all let's add the string needed to mount the volume in the fstab:
//x.x.x.x/remoteName  /media/samba cifs username=alex,password=,uid=501,noauto 0 0
where x.x.x.x is the address of the server

then set up a cron job doing the work everyday at 8am (I like to wake up early when it's a matter of someone else ;D): 
$ crontab -l
0 8 * * * /home/alex/transfer.cron >/dev/null 2>&1

then write the script doing the retrieve so that it write the .ntrc with the correct file without transferring EVERYTHING everyday: 

#!/bin/sh
NOME=`/bin/date --date "1 days ago" +"nome%Y%m%d.pdf"` 
cat /home/alex/.netrc_tmpl |sed -e "s%2BETRASFERRED%$NOME%">/home/alex/.netrc
chown alex /home/alex/.netrc
chmod 600  /home/alex/.netrc
sudo umount /media/samba
mount /media/samba

based on : 
>cat .netrc_tmpl 
machine ftp.server.eu login name@somewhere.it password xxxxxx macdef
init
lcd /media/samba
cd /listing
prompt off
bin
mput 2BETRASFERRED
quit

enjoy the reading after every breakfast 


note: to change the date in the past or in the future refer to: http://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html

custom solutions for everything 
http://lxphotostudio.mine.nu


No comments:

Post a Comment