Execute python file, FTP output to another server

Greetings all,

We are implementing a new tool called URLwatch which is a python utility. Here are the requirements.

1) Run every 10 seconds
2) Execute the python script
3) Output file gets generated, FTP it to a differernt server

I gave no idea how to do this and management needs a demo ASAP. Here is what I am thinking

BASH, btw.

dtstr=`date "+%x %X"`

function urlWatch {
for i in `echo  SOURCE
do
  if [ -e $i ] ; then
    echo .
    FTP COMMAND TO NEW SERVER  
    if [ -z $? ] ; then
      exit
    fi
  fi
done
}

while [ 1 ]
do

   # Initial Move
   SOURCE=PYTHONSCRIPT
   urlWatch

   sleep 10
done

Do you know how the single steps are done?

I do not unfortunately

Here is a simple example to get you started, remember that ftp is pretty insecure, and the password will be sent across the network in plain text. If could be worth using sftp (secure ftp) instead, especially if this is across the internet.

Also note this does nothing to guarantee the file is successfully sent before removing local version. If these files contain data you care about some checks should be done to ensure it's received intact before removing the local version.

FTP_SERVER=jeffsFTP
FTP_USER=upload
FTP_PASS=paSSword
FTP_DEST=/incomming

while true
do
    timestamp=$(date +'%Y%m%d%H%M%S')
    /usr/local/bin/PYTHONSCRIPT 2>&1 > /tmp/py${timestamp}
    ftp -n $FTP_SERVER <<SCRIPT_END
    quote USER $FTP_USER
    quote PASS $FTP_PASS
    cd $FTP_DEST
    put /tmp/py${timestamp}  py${timestamp}.transfer
    rename py${timestamp}.transfer py${timestamp}.ready
    quit
SCRIPT_END
    rm -f /tmp/py${timestamp}
    sleep 10
done

Here we timestamp each file with date and time, transfer it to a .transfer file and rename to .ready (this helps to avoid the dest server processing the file before it's completely transferred).