Skip to content

Instantly share code, notes, and snippets.

@mlgill
Last active December 25, 2015 08:59
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 mlgill/6951180 to your computer and use it in GitHub Desktop.
Save mlgill/6951180 to your computer and use it in GitHub Desktop.
#!/bin/zsh
#### BEGIN USER CONFIG OPTIONS ####
# Path to the data file to watch for modifications
local_progress_file="/path/to/file_that_is_periodically_modified"
# Interval in minutes to wait between queries
# Must be an integer
interval_min=30
# User account and hostname of Mac where you will be notified
dest_user=your_login_name
dest_address=your_mac_hostname
# Set to 1 to enable data synchronization or 0 to disable
data_sync=1
# Paths for data synchronization
local_data_path="/path/to/local/data/directory"
remote_data_path="/path/to/remote/data/directory"
#### END USER CONFIG OPTIONS ####
# Calculate time to wait between checks in seconds
(( sleep_sec = $interval_min * 60 ))
# Check if the progress file exists
if [[ -f ${local_progress_file} ]]; then
# Perform checks until the script is killed
while ((1)); do
# Synchronize the data if appropriate
if (($data_sync)); then
rsync --recursive --update --delete --owner --group \
--perms --times --compress --rsh=ssh \
${local_data_path} ${dest_user}@${dest_address}:${remote_data_path}
fi
# Check if the data file has been modified within the time period
mod_file=`find ${local_progress_file} -mmin -${interval_min}`
# Set notification message based on modification time of data file
if [[ $mod_file == "" ]]; then
message_string="NOTE: Experiment is stalled or complete"
else
message_string="OK: Experiment still running"
fi
# Send the notification to your Mac
ssh ${dest_user}@${dest_address} 'echo `/usr/local/bin/growlnotify \
-p high -m "'$message_string'" -t "Experiment Update"`'
# Wait until it's time to check again
sleep $sleep_sec
done
else
# Data file not found
echo "File ${local_progress_file} not found."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment