Created
July 27, 2015 13:07
-
-
Save alecthegeek/d1e349338cd6438fd431 to your computer and use it in GitHub Desktop.
Pauses and Resumes data sync with cloud storage services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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