fi exit 0 +{endcode} + +{subsection: Copying a file from one node to another} + +Here is a more sophisticated example, using the nc program (netcat) to copy a +file from one machine to another. Note that there is no security at all in +this file copy, any process on the network can connect and send data to the listening process, so you'd only want to run this on a trusted, protected network. + +The submit file is the same as above, but the run.sh is a bit more involved: + +{code} +#!/bin/sh + +CONDOR_CHIRP=`condor_config_val LIBEXEC`/condor_chirp + +# Tell chirp where the chirp config file is +export _CONDOR_CHIRP_CONFIG=$_CONDOR_SCRATCH_DIR/.chirp_config + +if [[ $_CONDOR_PROCNO = "0" ]] +then + + # I'm the server + + # Start netcat listening on an ephemeral port (0 means kernels picks port) + # It will wait for a connection, then write that data to output_file + + nc -l 0 > output_file & + + # pid of the nc running in the background + NCPID=$! + + # Sleep a bit to ensure nc is running + sleep 2 + + # parse the actual port selected from netstat output + NCPORT=` + netstat -t -a -p 2>/dev/null | + grep " $NCPID/nc" | + awk -F: '{print $2}' | awk '{print $1}' + ` + + # grab the hostname + HOSTNAME=`hostname` + + $CONDOR_CHIRP set_job_attr JobServerAddress \"${HOSTNAME}\ ${NCPORT}\" + + # Do other server things here... + sleep 3600 + exit 0 +fi + + +if [[ $_CONDOR_PROCNO = "1" ]] +then + + # I'm the client + + sleep 20 + # Poll until the job attribute appears in the ad + + until $CONDOR_CHIRP get_job_attr JobServerAddress > /tmp/null 2>&1 + do + sleep 2 + done + + JobServerAddress=`$CONDOR_CHIRP get_job_attr JobServerAddress` + + host=`echo $JobServerAddress | tr -d '"' | awk '{print $1}'` + port=`echo $JobServerAddress | tr -d '"' | awk '{print $2}'` + + # Send the /etc/hosts file to the other side + nc $host $port < /etc/hosts + + # Don't do any other client stuff, just exit + exit 0 +fi + +exit 0 + + + {endcode}