#!/bin/bash
USER=${USER:-$1}
PATH=${PATH:-"/usr/local/bin:/usr/bin:/bin:/home/$USER/bin"}
## [USAGE] crontab -e
## Examples:
# Run every minute * * * * * ~/rtorrent_cron <username>
# every 10 minues */10 * * * * ~/rtorrent_cron
# on reboot @reboot ~/rtorrent_cron
# hourly @hourly ~/rtorrent_cron
#COMMAND="dtach -n /home/$USER/rtorrent.dtach rtorrent"
#COMMAND="tmux new -s rtorrent -d rtorrent"
COMMAND="screen -dmS rtorrent rtorrent"
## Uncomment if you want to log these actions
#LOG=/home/$USER/rtorrent_cron.log
#MSG="$(date "+[%d %b %H:%M:%S]") CRON: Starting rtorrent..."
start_rtorrent() { #test if rtorrent is running, if not, start it
if [[ -z $(pgrep -u $USER rtorrent) ]]; then
$($COMMAND) && sleep 1
fi
}