Skip to content

Instantly share code, notes, and snippets.

@annawoodard
Created March 23, 2021 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annawoodard/49928dde66f748ea284b2394ec2d4a17 to your computer and use it in GitHub Desktop.
Save annawoodard/49928dde66f748ea284b2394ec2d4a17 to your computer and use it in GitHub Desktop.
rsync radiology -> cri
LOCK_NAME="chimec_sync"
LOCK_DIR='/tmp/'${LOCK_NAME}.lock
PID_FILE=${LOCK_DIR}'/'${LOCK_NAME}'.pid'
if mkdir ${LOCK_DIR} 2>/dev/null; then
# If the ${LOCK_DIR} doesn't exist, then start working & store the ${PID_FILE}
echo $$ > ${PID_FILE}
rsync --remove-source-files -avPz /mnt/hiro/ t.cri.awoodard@gardner.cri.uchicago.edu:/gpfs/data/huo-lab/Image/ChiMEC/ >& /home/annawoodard/rsync.log
rm -rf ${LOCK_DIR}
exit
else
if [ -f ${PID_FILE} ] && kill -0 $(cat ${PID_FILE}) 2>/dev/null; then
# Confirm that the process file exists & a process
# with that PID is truly running.
echo "Running [PID "$(cat ${PID_FILE})"]" >&2
exit
else
# If the process is not running, yet there is a PID file--like in the case
# of a crash or sudden reboot--then get rid of the ${LOCK_DIR}
rm -rf ${LOCK_DIR}
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment