Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Created July 27, 2015 13:07
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 alecthegeek/d1e349338cd6438fd431 to your computer and use it in GitHub Desktop.
Save alecthegeek/d1e349338cd6438fd431 to your computer and use it in GitHub Desktop.
Pauses and Resumes data sync with cloud storage services
#!/usr/bin/env bash
# Pause the following Cloud Storage Services
services=('Google Drive' Copy Dropbox)
# Based on ideas and code on https://github.com/tjluoma/dropbox-pause-unpause
if [[ $0 =~ pause || $1 =~ pause ]] ; then
command=STOP
elif [[ $0 =~ resume || $1 =~ resume ]] ; then
command=CONT
else
echo invalid option. Must be pause or resume. Not \""$0" "$@"\"
exit
fi
for i in "${services[@]}" ;do
x=waiting
while [[ $x = waiting ]] ; do
psi=($(ps cx | awk '/'"$i"'/{print $1 " " $3}'))
xpid=${psi[0]}
xstatus=${psi[1]}
if [[ $command == STOP && $zstatus == U ]] ; then
echo Sleeping for 1s as Process $i PID is $xpid status is $xstatus
sleep 1
else
echo Running Command $command on Process $i PID is $xpid status is $xstatus
kill -$command $xpid
x=done
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment