need a perlscript to read from a text file and transfer files via ftp
hi
I know sometimes it's not easy, but I need a perl script rather urgently I get 5 times a day, 3 files transfered : one info.txt and two data files: info.txt SN00001 SN00002 the name of info.txt never changed, but names of data files yes. but the names in info.txt file (left) are always the same like names of data files. info.txt file looks: ------------------------------------------------------------- SN00001 RN20001 SN00002 RN20002 -------------------------------------------------------------- the perl script should first open the info.txt file, read the name of the first file (like left in info.txt), rename the first file to RN20001 (like right in info.txt ), transfer via ftp, wait 5 minutes, rename the second file to RN20002 and transfer via ftp to the same remote server. I mean to wait for 5 minutes before the second file will be transfered. this is very important. and this script should not transfer any files without info.txt if someone can help me would be great, before I am lost ! best regards cccc |
Re: need a perlscript to read from a text file and transfer files via ftp
Quote:
I'm not a perl dude but this should be easy in shell. Run it five times a day using cron. ALtenatively you can write a generic script which polls a give directory in an infinite loop and performs the necessary action .. you get the idea. First create a .netrc file and put the ftp user and password there #/bin/sh ftpdata(){ echo "ftping data" ftp $REMOTESERVER<<EOF cd $REMOTEDIR put $DATADIR/LOCALFILE $REMOTEDIR/REMOTEFILE bye EOF } DATADIR=your data directory when files are received ARCHIVEDIR=where you want the old data archived REMOTEDIR=directory where you want ftping REMOTESERVER=remote host LOCALFILE= REMOTEFILE= if [ ! -f $DATADIR/info.txt ]; then echo "Nothing to process" exit 0 fi LOCALFILE=`awk '{ if ( NF == 0 ) print $1}' $DATADIR/info.txt` REMOTEFILE=`awk '{ if ( NF == 0 ) print $2}' $DATADIR/info.txt` ftpdata ; mv $DATADIR/LOCALFILE $ARCHIVEDIR/$LOCALFILE.`date +'%d%m%Y.%T'` sleep 300 LOCALFILE=`awk '{ if ( NF == 1 ) print $1}' $DATADIR/info.txt` REMOTEFILE=`awk '{ if ( NF == 1 ) print $2}' $DATADIR/info.txt` ftpdata ; mv $DATADIR/LOCALFILE $ARCHIVEDIR/$LOCALFILE.`date +'%d%m%Y.%T'` mv $DATADIR/info.txt $ARCHIVEDIR/info.txt.`date +'%d%m%Y.%T'` |
hi linuxxed
thank you very much ! it's a great script and works well. kind regards cccc |
All times are GMT -5. The time now is 03:29 AM. |