Execute python file, FTP output to another server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute python file, FTP output to another server
# 1  
Old 12-16-2014
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.

Code:
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

# 2  
Old 12-16-2014
Do you know how the single steps are done?
# 3  
Old 12-16-2014
I do not unfortunately
# 4  
Old 12-16-2014
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.

Code:
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

creating separate output file for each input file in python

Experts, Need your help for this. Please support My motive is to create seperate output file for each Input Files(File 1 and File2) in another folder say(/tmp/finaloutput) Input files File 1(1.1.1.1.csv) a,b,c 43,17104773,3 45,17104234,4 File 2(2.2.2.2.csv) a,b,c 43,17104773,1... (2 Replies)
Discussion started by: as7951
2 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

How to execute a batch file containing ftp commands??

hi, is there a way i can execute a batch file containing ftp commands like we execute sftp batch file. sftp -b batchfile user@server > output how to create a batch file for ftp executing command and how to run the batch file from a shell script? (2 Replies)
Discussion started by: Little
2 Replies

4. Shell Programming and Scripting

Shell script to copy a file from one server to anther server and execute the binary

Hi , Is there any script to copy a files (weblogic bianary + silent.xml ) from one server (linux) to another servers and then execute the copy file. We want to copy a file on multiple servers and run the installation. Thanks (1 Reply)
Discussion started by: Nawrajesh
1 Replies

5. Shell Programming and Scripting

Plot python script output to file

Hi all, I`m trying to generate some plots using a python package named splicegrapher. I have access to a cluster which does not allow X11 forwarding and as a result I get RuntimeError: could not open display error when I use one of the plotting scripts (attached). How do I modify the script... (1 Reply)
Discussion started by: newbie83
1 Replies

6. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

7. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

8. Shell Programming and Scripting

Dowloading a File from FTP Server to a local Server where User Id's are different

Hi, The Setup is like this. I'm connecting to Unix machine from my local machine. After connecting to Unix M/c, i need to connect FTP server. Am successful in connecting to FTP server, but am not able to download the file from the ftp server to my local machine. I have different user id's and... (1 Reply)
Discussion started by: ranjith_taurean
1 Replies

9. Shell Programming and Scripting

how to move a file from one server to another server using FTP in shell script?

I have a file --> file1.txt i need to copy this file to another server using FTP....the 2 servers are server1 and server2..may i know how to write a script that can do this? thanks in advance! Im a newbie to this... (4 Replies)
Discussion started by: forevercalz
4 Replies

10. UNIX for Dummies Questions & Answers

Remote execute a file via ftp

How can I execute a script on a unix server via ftp from a Windows machine?? Can't use cron/at to schedule the execution and don't want to open up a telnet session just to do it. I want to be able to kick it off after I send the script over on a nightly basis. Reason is script parameter changes... (4 Replies)
Discussion started by: giannicello
4 Replies
Login or Register to Ask a Question