Last active
October 31, 2015 12:28
-
-
Save ericoporto/1ec7a9eac17bb64e4f41 to your computer and use it in GitHub Desktop.
Script to configure Transmission on Raspberry Pi to only run when I'm not home - afternoon - or when I'm sleeping.
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
#!/bin/bash | |
# Run this script WITHOUT Sudo. | |
# This script assumes you have installed transmission-daemon | |
# on your Raspberry Pi (or whatever where you are running it...) | |
# Running it will use cron to pause and unpause all your torrents | |
# at specific times. | |
# Right now you, no torrents will be downloaded from 5 am to 9 am and | |
# also no torrents will be downloaded from 5 pm to 11 pm. | |
THISFOLDER=`pwd` | |
THISNOW=`date +"%m%d%y-%H%M%S"` | |
PAUSEALL="transmission-remote --torrent all --stop" | |
RESUMEALL="transmission-remote --torrent all --start" | |
for i in "$@" ; do | |
if [[ $i == "--uninstall" ]] ; then | |
crontab -l | while read -r; do | |
[[ $REPLY = *$PAUSEALL* ]] || [[ $REPLY = *$RESUMEALL* ]] && continue | |
printf '%s\n' "$REPLY" | |
done | crontab - | |
echo " " | |
echo "removed entries from cron" | |
echo " " | |
exit | |
fi | |
if [[ $i == "--help" ]] ; then | |
echo "usage" | |
echo "$0 " | |
echo " :: configure cron to pause transmission when you are awake at home " | |
echo "" | |
echo "$0 --uninstall " | |
echo " :: removes any modifications from this file on cron " | |
echo "" | |
echo "$0 --help " | |
echo " :: show this message " | |
exit | |
fi | |
done | |
#keep a copy of current crontab | |
crontab -l > original.$THISNOW.cronfile | |
#let's make a new crontab | |
crontab -l | while read -r; do | |
[[ $REPLY = *$PAUSEALL* ]] || [[ $REPLY = *$RESUMEALL* ]] && continue | |
printf '%s\n' "$REPLY" | |
done | crontab - | |
crontab -l > /tmp/new.cronfile | |
printf "\n...adding to cron...\n" | |
#echo new cron into cron file | |
# first the weekdays | |
echo "0 5,17 * * 1-5 $PAUSEALL" >> /tmp/new.cronfile | |
echo "0 9,23 * * 1-5 $RESUMEALL" >> /tmp/new.cronfile | |
# now the weekends | |
echo "0 9 * * 0,6 $PAUSEALL" >> /tmp/new.cronfile | |
echo "0 23 * * 0,6 $RESUMEALL" >> /tmp/new.cronfile | |
echo " " >> /tmp/new.cronfile | |
#install new cron file | |
crontab /tmp/new.cronfile | |
#remove new cron file | |
rm /tmp/new.cronfile | |
#say success | |
printf "\nTransmission should only work when you are not home.\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment