Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.
Showing posts with label monitor. Show all posts
Showing posts with label monitor. Show all posts

Cooler CPU


#!/bin/bash
# Filename: cpulimit-ghb.sh
# Version.: 09032017
# Author..: robz
# I know, I'm cheap, I should buy a better than stock cooling fan, but....
# Dynamically use the cpulimit utility to keep cpu within a sane temperature
# range when using Handbrake or another resource hammering program.
# sudo apt install cpulimit lmsensors - use PPA for the latest Handbrake.
# Dependant on the output of "sensors" you may need to tweak line ##.

if [ "$UID" != "0" ]; then                          # Get root privilege.
    sudo -k; exec gksudo --message "$(echo\
    'Enter your password please, you need root';\
    echo 'privileges to run cpulimit effectively.')"\
    "$0"
fi

max='67'                                            # Maximum temperature°C.
cores='2'                                           # Number of cpu cores.
prog='/usr/bin/ghb'                                 # Program you're limiting.
limit=$((100*cores))                                # Total 100% limit range.
base="$limit"

while [[ "$(pidof "$prog")" ]]; do
    temp=$(sensors | grep 'CPU:' | cut -c18-19)     ## Get cpu temperature.
    if [[ "$temp" -gt "$max" && "$limit" -gt '25' ]]; then
        killall /usr/bin/cpulimit                   # Kill old process.
        ((limit-=25))                               # Increment limit down.
        cpulimit -qb -P "$prog" -l "$limit"         # Start new process.
    elif [[ "$temp" -lt "$max" && "$limit" -lt "$base" ]]; then
        killall /usr/bin/cpulimit
        ((limit+=25))                               # Increment limit up.
        cpulimit -qb -P "$prog" -l "$limit"
    fi
    sleep 5
done

killall /usr/bin/cpulimit
exit


Basic PVR

#!/bin/bash
# Filename: mypvr.sh
# Version: 081211
# Author: robz
# This script uses http://ezrss.it to check for the lastest episodes of your
# favorite tv shows, which you'll have listed in the "followed-shows" file.
# Run mypvr.sh from your chosen directory. First, the above list file will be
# set up, once this is done the script can be controlled via a crontab or on
# PC startup, or both. Here's a crontab to check for new shows every 2 hours.
# 25 */2 * * * export DISPLAY=:0 && /$HOME/PVR/mypvr.sh >/dev/null 2>&1
# Selected .torrent trackers will be sent to your "Downloads" directory ready
# to be picked up by "Transmission" gui/daemon or any other client that can be
# set to auto-load from a monitored directory.

SHOW_NAME_EXACT=""                  # Allow some search leeway.
QUALITY="hdtv"                      # HDTV standard quality.
QUALITY_EXACT="true"                # Only hdtv not 720p - no huge files.
DWNLDS="$HOME/Downloads"            # Default Downloads, change if you like.
green="<span color=\"#008000\">"    # Green ok! :p

func_form_url ()                                    # Create web search url.
{
WEBSITE="http://ezrss.it/search/index.php?show_name="$SHOW_NAME"&\
show_name_exact=$SHOW_NAME_EXACT&date=&quality=$QUALITY&\
quality_exact=$QUALITY_EXACT&release_group=&mode=simple"
}

cd
"$(dirname "$0")"                                # Do cd to "mypvr.sh" dir.

trap "rm -f "newlist" "urllist"; exit" \
INT TERM EXIT                                       # Clean up cruft on close.

if [ ! -e "donelist" ]; then touch donelist; fi     # Check donelist exists.
if [ ! -e "followed-shows" ]; then                  # Check shows list exists.
cat > followed-shows << EOF
# Type the names of tv shows to be followed into this list.
# Hash commented, like this line, and blank lines will be ignored.
# To stop a show search, comment "#" the line or delete it :)

Spooks
#Terra Nova < examples, delete and replace with yours.
Dexter

# End of list - a blank line is required above this line.
EOF
gedit followed-shows                                # Edit new shows list.
exit; fi

while read SHOW_NAME; do                            # Read followed-shows list.
    if [[ "${SHOW_NAME:0:1}" != "#" && -n "$SHOW_NAME" ]]; then
        SHOW_NAME=$(echo "$SHOW_NAME" | sed -e 's/ \+/+/g')
        func_form_url                               # Create custom url.
        # Get web pages for shows, take episode at top of page - newest.
        wget -q --random-wait -O - $WEBSITE |\
        egrep -om1 "http:.*.torrent" >> urllist
    fi
done < followed-shows                               # Feed followed-shows.

sort -u urllist > newlist                           # De-dupe, make copy.

# Whittle away the URL bumf for a naked "newlist".
sed -i 's#http:/[^",]*/##' newlist
sed -i 's/\([Ee][0-9][0-9]\)\+.*/\1/' newlist       # S01E02 - s01e02.
sed -i 's/\([Xx][0-9][0-9]\)\+.*/\1/' newlist       # 1X02 - 1x02 - 01X02.
#sed -i 's/\([0-9][0-9][0-9]\)\+.*/\1/' newlist     # 102 ? (V2009)?! aah!
sed -i '/torrent/d' newlist                         # Remove strays.

sort newlist -o newlist                             # Sort stripped list.

NEW=$(comm --check-order -23 newlist donelist)      # Compare new/existing.
if [ -z "$NEW" ]; then exit; fi                     # $tring null? then exit.

for LINE in $NEW; do SEL+=" TRUE $LINE"; done       # Prepend entries "TRUE".

# Option for 10 mins to choose/cancel or it auto-downloads all new trackers.
CHOOSE=$(zenity --title "PVR" --timeout 600 --width 300 --height 225 \
--list --text "$green""There are new TV episodes available</span>" \
--checklist --column " #" --column "Download torrent trackers for:" $SEL)
EXITCODE="$?"

if [ "$EXITCCODE" = 1 ] || [[ "$EXITCODE" = 0 && -z "$CHOOSE" ]]; then
    exit                                            # Null entry or cancel.
elif [ -z "$CHOOSE" ]; then                         # $CHOOSE empty, use $NEW.
    CHOOSE=$(echo $NEW | sed 's/  */|/g')           # Add "|" egrep delimiters.
    zenity --notification --text "Auto download of latest TV trackers"\
    & disown
fi

timeout 60 \
wget --quiet --no-clobber --random-wait --directory-prefix=$DWNLDS \
--input-file=$(egrep $(echo $CHOOSE) urllist)       # Go "wget" the trackers.

CHOOSE=$(echo "$CHOOSE" | sed 's/|/ /g')            # Strip delimiters.

# If tracker has downloaded correctly, make entry to "donelist".
for LINE in $CHOOSE; do
    if [ $(ls "$DWNLDS" | grep $LINE) ]; then echo "$LINE" >> donelist
    elif [ -z $PID ]; then zenity --notification\
        --text="`echo -e "One or more trackers has failed to download.\
        \nNext try is scheduled for $(date --date='+2 hours' +%H:25) hours."`"\
        & disown
        PID=$!                                      # Just one notification.
    fi
done

sort donelist -o donelist                           # Sort new "donelist".

notify-send -i '/usr/share/icons/hicolor/scalable/apps/transmission.svg' \
"Tracker files downloaded" "$(ls "$DWNLDS" | grep "\.torrent")" &


Television Episode Downloader

#!/bin/bash
# Filename: ezrss
# Version 091110
# Author: robz
# Download trackers from "EZrss" & monitor the "Torrents/Incomplete" folder.
# I have "unmetered" bandwidth in the small hours but dislike leaving my PC
# on all the time, this script suspends & resumes the PC within that timeslot.
# You will need "rtcwake" from the repositories and "shutdown" may need
# adding to the sudoers list.
# In a terminal (omitting all quote marks) do "sudo visudo", at the bottom of
# the listed items click Enter for a new line and paste this entry:
# "%user ALL=NOPASSWD: /sbin/shutdown" replacing "user" with your user name,
# click Escape and do ":wq" Enter to save and exit.
# Be careful editing sudoers as mistakes can cause problems.
# Ref: man visudo - read this if you're at all unsure ---- read it anyway.
# Use this line for your menu or panel launcher, alter to suit ---
# gnome-terminal --geometry 110x50+20+50 -x /home/"user?"/".scripts?"/ezrss

## Vars
DIRI=/home/$USER/Torrents/Incomplete/           # Incomplete downloads.
DIRC=/home/$USER/Torrents/Complete/             # Complete downloads.
FILE=/tmp/ezrss.file                            # Episodes list from EZrss.
TRKRS=/tmp/trackers.file                        # Episodes selected.
LOG=/home/$USER/Torrents/torrents.log           # Logfile.
TFDLD=/home/$USER/Downloads/                    # default .torrent dl dir.
IN=7200                                         # Default halt pc, in seconds.
SEED=600                                        # Default seed, in seconds.
EVERY=10                                        # Test dir every, in seconds.
SHOW_NAME_EXACT=""                              # Search leeway, leave blank.
QUALITY="hdtv"                                  # Look for HDTV quality.
QUALITY_EXACT="true"                            # Enforce only hdtv not 720p.
UMDL=02:15                                      # Unmetered download start.
AT=$(date -d $UMDL +%s)                         # Date/time re-start - epoch.
ENDS=$(date -d 0645 +%s)                        # End time for unmetered.
PROG="transmission-gtk"                         # Bittorrent Client.

get_shows() ## Function search and select shows ---------------------------##
{
echo -e "\033[36;1mDownload television shows torrents from EZrss--\n"
tput sc; tput setaf 6
SHOW_NAME=""
while [ "$SHOW_NAME" = "" ]; do
read -p "Enter name of show: " SHOW_NAME; tput cuu1; done
SHOW_NAME=`echo $SHOW_NAME | sed -e 's/ \+/+/g'`
# Form "EZrss" URL for search page, get results.
SITE="http://ezrss.it/search/index.php?\
show_name="$SHOW_NAME"&\
show_name_exact=$SHOW_NAME_EXACT&\
date=&\
quality=$QUALITY&\
quality_exact=$QUALITY_EXACT&\
release_group=&\
mode=simple"
wget -q -O - $SITE | egrep -o "http:.*.torrent" | sort -u -r > $FILE
tput rc; tput el; tput setaf 7
nl $FILE                                        # Number for easy selection.
echo; tput sc
ANS="0"
until [[ "$ANS" = "n" || "$ANS" = "q" ]]; do    # Not n or q? get more shows.
    tput setaf 6; tput el
    read -p "Select an index number (q)uit (n)ext - press ENTER " ANS
    if [[ "$ANS" != "n" && "$ANS" != "q" ]]; then
        sed "$ANS"!d $FILE >> $TRKRS
        tput setaf 7; tput rc; tput el
        cat < $TRKRS
    fi
done
if [ "$ANS" = "q" ]; then clean; fi             # If quit clean temps & exit.
}

deferred_start() ## Function suspend and re-start later -------------------##
{
sudo /bin/true                                  # Get root privileges.
if [ "$AT" -lt $(date +%s) ]; then              # Is time set already gone?
    AT=$((AT + 86400))                          # If true then add a day.
fi
echo "Torrent log for "$(date +%a" "%x) >> $LOG
echo "Suspend PC start option chosen -------" >> $LOG
tput setaf 3
echo -e "To cancel - Ctrl+c within the next 10 seconds.\n"
tput setaf 7; sleep 10
AT=$(($AT - `date +%s`))                        # Calc. wake in $AT seconds.
sudo killall rtcwake; clear                     # Kill any residual process.
poff -a                                         # Stop ADSL.
sync && sudo rtcwake -u -s $AT -m on &          # Set wake-up time.
sleep 2; sudo /usr/sbin/pm-suspend              # Workaround rtcwake bug.
##### PC suspended here. Restart time is set with the "UMDL" in Vars above ##
xset dpms force off                             # Awake with VDU off.
CHECK=0; sleep 20; pon adsl; sleep 20           # Start & test for ADSL.
while ! ping -q -c 1 www.google.com > /dev/null && let "CHECK += 1"; do
    if [ "$CHECK" -gt "18" ]; then              # Ping for 180 seconds.
        echo "Torrent log for "$(date +%a" "%x) >> $LOG
        echo "ADSL failed to reconnect - bollocks!!" >> $LOG
        haltpc                                  # No internet? call shutdown.
    fi
sleep 10
done
}

stats() ## Function download/upload stats ---------------------------------##
{
for n in {2..5}; do
    RAW=`vnstat --dumpdb -i ppp0 | grep "h;$n;"`
    UP=$(echo $RAW | cut -d ";" -f5)
    DOWN=$(echo $RAW | cut -d ";" -f4)
    let "DOWN_TOTAL += DOWN"
    let "UP_TOTAL += UP"                        # Loop vnstat for traffic.
done
UP_TOTAL=$(echo "scale=2; $UP_TOTAL / 1024" | bc)
DOWN_TOTAL=$(echo "scale=2; $DOWN_TOTAL / 1024" | bc)
echo "Traffic for this session:" >> $LOG
echo -n "Up: "$UP_TOTAL"MiB | Down: "$DOWN_TOTAL"MiB | " >> $LOG
echo -n "Total: "$(echo "scale=2; $UP_TOTAL + $DOWN_TOTAL" | bc) >> $LOG
echo -e "MiB\nThese figures might also include the auto update cron job\n"\
"check the Update Manager for new downloads.\n" >> $LOG
}

haltpc() ## Function shutdown nicely  -------------------------------------##
{
killall -w -q "$PROG" && stats
echo "Run completed, PC shutdown at: "$(date +%H:%M:%S) | tee -a $LOG
echo -e "\n==============================================================\n"\
>> $LOG
# "shutdown" needs to be added to sudoers list for next bit to work.
sync && sudo shutdown -h now
exit
}

clean() ## Function remove temporary files & quit script ------------------##
{
rm -f $TRKRS; rm -f $FILE; rm -f $TFDLD/*.torrent*; exit
}

## Start here ######
get_shows                                       # Function get_shows.
ANS="0"
until [[ "$ANS" = "n" || "$ANS" = "q" ]]; do    # Not n or q? then more shows.
    tput sc; tput cuu1; tput el
    echo -ne "\nAnother show?  (y)es (q)uit (n)ext "
    read ANS
    if [ "$ANS" = "y" ]; then
        clear
        get_shows; ANS="0"
    elif [[ "$ANS" != "n" && "$ANS" != "q" ]]; then
    tput cuu1; tput el; echo "I don't understand your input"
    sleep 2; tput cuu1
    fi
done
if [ "$ANS" = "q" ]; then clean; fi             # If quit clean temps, exit.

# Get tracker files
wget -q -nc -P $TFDLD -i $TRKRS
tput setaf 6; tput cuu1; tput el
echo -e "Tracker files have downloaded -----------------------------------\n"
rm -f $TRKRS; rm -f $FILE                       # Tidy up tmp files.

## Start now or suspend and resume at $UMDL.
tput bold; tput setaf 6;
ANS=" "
until [[ "$ANS" = "y" || "$ANS" = "q" || "$ANS" = "n" ]]; do
    read -p "Suspend now and restart at $UMDL? (y)es (q)uit (n)ext " ANS
    if [[ "$ANS" = "y" && `date +%s` -gt "$AT" && `date +%s` -lt "$ENDS" ]];
    then
        read -p "You're ADSL is unmetered! start now (q)uit (n)ext " ANS
    fi
done
if [ "$ANS" = "q" ]; then
    clean                                       # If quit clean temps, exit.
elif [ "$ANS" = "y" ]; then
    deferred_start                              # func deferred_start
else
    echo "Download now option chosen -----" tee -a $LOG
fi

## Start Bittorrent client Transmission GUI.
tput bold; tput setaf 7; clear
echo "Torrent log for "$(date +%a" "%x) >> $LOG
# TODO
"$PROG" &
# Required parameters already set for GUI, but maybe the daemon or remote
# option would be a better choice to avoid potential config. conflicts.

## Wait for files to appear in /Incomplete, loop here until true.
while $(ls -A $DIRI); do
    tput cup 0 0; tput smso
    printf "\r%s"">>>>> Waiting for files in >>>>>\n$DIRI"
    sleep 5
done
tput rmso; clear

## Write details of download to log.
tput bold; tput setaf 6
echo -e "Monitor \"$PROG's\" working directory for \n\
completion of currently downloading torrents.\n"
echo -n "Directory: " | tee -a $LOG
tput setaf 7
echo -e "\"$DIRI\"" | tee -a $LOG
tput setaf 6; tput sc
echo "Waiting for compliant peers"; sleep 180
tput rc
echo "Files found:               " | tee -a $LOG
tput setaf 7
echo -e "$(ls -1 $DIRI)\n" | tee -a $LOG        # List and log.
tput setaf 6
echo -e "PC will be shut down when seeding is complete"
echo -e "Run started at: "$(date +%H:%M:%S) | tee -a $LOG
DSET=$((`date +%s`+IN))                         # Default shutdown from epoch.
echo -e "and will finish no later than: "$(date -d @$DSET +%H:%M:%S)"\n"
tput sc
echo -e "The directory is monitored at $EVERY""s intervals."

## Start timer
#  Check /Incomplete dir. for content, if [time up or empty] then next.
CHECK=1
while [[ $CHECK*$EVERY -lt $IN && "$(ls -A $DIRI)" ]]; do
    printf "\r%s""Working..............checks made so far: ""$CHECK "
    sleep $EVERY
    CHECK=$((CHECK+1))
done
echo

## If /Incomplete dir. is true then shutdown function.
if [[ "$(ls -A $DIRI)" ]]; then
    tput setaf 1; tput rc
    echo -e "--------------------------------------------------------------\n\
Default time limit reached torrents incomplete!\n\
$(ls -1 $DIRI)\n\
--------------------------------------------------------------" | tee -a $LOG
    haltpc                                       # shutdown function.
fi

## Torrents completed before default? then seed.
tput rc
echo -e "--------------------------------------------------------------\n\
Completed files transferred out at $(date +%T)" | tee -a $LOG
echo -n "to directory " | tee -a $LOG
tput setaf 7
echo -e "\"$DIRC\"\n\
--------------------------------------------------------------" | tee -a $LOG
echo -ne "\"$DIRI\""
tput setaf 6
echo -e " is now empty."
DIFF=$((DSET-`date +%s`))                       # default time remaining.
if [ "$DIFF" -le "$SEED" ]; then
    SEED=$DIFF
fi
echo -e "Torrent seeding time is set for $SEED"

## Seed time allocation.
if [ "$SEED" -gt "0" ]; then
    echo -e "Torrent residual seed $SEED seconds" >> -a $LOG
    tput setaf 1
    for i in $(eval echo {$SEED..0}); do    # count down from seed value.
        printf "\r%s""This computer will shut down in: "$i
        tput el
     sleep 1
    done
fi
echo
haltpc                                      # shutdown function.



Powered by ScribeFire.

Bittorrent Monitor

#!/bin/bash
# Filename: dlfmon
# Author: robz
# Version: 091110
# Used with "Transmission" to monitor the "Torrents/Incomplete" folder.
# I have "unmetered" bandwidth in the small hours but dislike leaving my PC
# switched on all the time, (greener:)) so this is what this script is for.
# You may need "trickle" and "rtcwake" from the repositories and "shutdown"
# added to the sudoers list.
# In a terminal do "sudo visudo" then at the bottom of the list paste this:
# "%user ALL=NOPASSWD: /sbin/shutdown" all without quotes and replacing "user"
# with your user name, then do ":wq" to save and exit. Ref: man visudo.
# Use this line for your launcher, alter to suit.
# gnome-terminal --geometry 50x29+20+50 -x /home/user/.scripts/dlfmon

## Vars.
IN=7200                                     # Halt pc in - seconds.
SEED=600                                    # Default seed for - seconds.
EVERY=30                                    # Test dir every - seconds.
UMDL=02:15                                  # Unmetered download start.
CHECK=1                                     # Checks done counter.
AT=`date -d $UMDL +%s`                      # Date/time re-start - epoch.
DIRI=/home/$USER/Torrents/Incomplete/
DIRC=/home/$USER/Torrents/Complete/
LOG=/home/$USER/Torrents/torrents.log
PROG="transmission-gtk"                     # monitor this prog.

stats() ## Function download/upload stats ---------------------------------##
{
for n in {2..5}; do
    RAW=`vnstat --dumpdb -i ppp0 | grep "h;$n;"`
    UP=$(echo $RAW | cut -d ";" -f5)
    DOWN=$(echo $RAW | cut -d ";" -f4)
    let "DOWN_TOTAL += DOWN"
    let "UP_TOTAL += UP"                        # Loop vnstat for traffic.
done
UP_TOTAL=$(echo "scale=2; $UP_TOTAL / 1024" | bc)
DOWN_TOTAL=$(echo "scale=2; $DOWN_TOTAL / 1024" | bc)
echo "Traffic for this session:" >> $LOG
echo -n "Up: "$UP_TOTAL"MiB | Down: "$DOWN_TOTAL"MiB | " >> $LOG
echo -n "Total: "$(echo "scale=2; $UP_TOTAL + $DOWN_TOTAL" | bc) >> $LOG
echo -e "MiB\nThese figures might also include the auto update cron job\n"\
"check the Update Manager for new downloads.\n" >> $LOG
}

## shutdown nicely function.
haltpc ()
{
killall -w -q "$PROG" && stats
echo "Run completed, PC shutdown at: "$(date +%H:%M:%S) | tee -a $LOG
echo -e "\n==============================================================\n"\
>> $LOG
# "shutdown" needs to be added to sudoers list for next bit to work.
sync && sudo shutdown -h now
exit
}

## Suspend, Wait or Start now.
tput bold; tput setaf 6;
ANS=""
read -p "Do you wish to suspend and restart at $UMDL? (y)es (n)ext " ANS
if [ "$AT" -lt `date +%s` ]; then               # Is time set already gone?
    AT=$((AT + 86400))                          # if true add a day.
fi
WAKE=$(($AT - `date +%s`))                      # Calc. wake in $AT seconds.
if [ $ANS = "y" ]; then                         # Deferred start yes?
    sudo /bin/true                              # Get root privileges.
    tput setaf 3
    sudo killall rtcwake; clear                 # Kill any residual process
    echo "Suspend until $UMDL option chosen -------" | tee -a $LOG
    echo -e "To cancel - Ctrl+c within the next 10 seconds.\n"
    sleep 10; poff -a                           # Dissconnect
    sync && sudo rtcwake -u -s $WAKE -m on &    # Set wake-up (background).
    sleep 2; sudo /usr/sbin/pm-suspend          # Workaround for rtcwake bug
    ############################################# PC suspended here ########
    xset dpms force off                         # Awake with VDU off.
    CHECK=0; sleep 20; pon adsl; sleep 20       # Start & test for ADSL.
    while ! ping -c 1 www.google.com > /dev/null && let "CHECK += 1"; do
        if [ "$CHECK" -gt "18" ]; then          # Ping for 180 seconds.
            echo "Torrent log for "$(date +%a" "%x) >> $LOG
            echo "Network connection unreachable" >> $LOG
            haltpc                              # No internet? call shutdown.
        fi
    sleep 10
    done
elif [ $ANS = "n" ]; then
    clear
    read -p "Do you wish to countdown to $UMDL (y)es (n)ext " ANS
    if [ $ANS = "y" ]; then
        clear; tput setaf 3; tput civis
        echo "Wait until $UMDL option chosen -------" | tee -a $LOG
        for i in $(eval echo {$WAKE..0..10}); do
            printf "\r%s""Countdown to unmetered ADSL: "$i" seconds     "
            tput el
            sleep 10
        done
    fi
fi

## Start Bittorrent client Transmission GUI, with limited bandwidth
echo "Torrent log for "$(date +%a" "%x) >> $LOG
"$PROG" &
# TODO
# Required parameters already set for GUI, but maybe the daemon or remote
# option would be a better choice to avoid potential config. conflicts.

## Check dir, ready/or not? - start process when true.
clear; tput bold
while $(ls -A $DIRI); do
    tput cup 0 0; tput smso
    printf "\r%s"">>>>> Waiting for files in >>>>>\n$DIRI"
    sleep 5
done
clear; tput rmso

## Write details of download to log.
tput bold; tput setaf 6; tput civis
echo -ne "Directory: " | tee -a $LOG
tput setaf 7
echo -e "\"$DIRI\"" | tee -a $LOG
tput setaf 6; tput sc
echo "Waiting 60 seconds for compliant peers"; sleep 60
tput rc
echo "Files found:                          " | tee -a $LOG
tput setaf 7
echo -e "$(ls -1 $DIRI)\n" | tee -a $LOG        # List and log.
tput setaf 6
echo -e "PC will be shut down when seeding is complete"
echo -e "Run started: "$(date +%a" "%x" at: "%H:%M:%S) | tee -a $LOG
DSET=$((`date +%s`+IN))                         # Default shutdown from epoch.
echo -e "and will finish no later than: "`date -d @$DSET +%H:%M:%S`"\n"
tput sc
echo -e "The directory is monitored at $EVERY""s intervals."

## Start timer
#  Check /Incomplete dir. for content, if [time up or empty] then next.
CHECK=1
while [[ $CHECK*$EVERY -lt $IN && "$(ls -A $DIRI)" ]]; do
    printf "\r%s""Working..............checks made so far: ""$CHECK "
    sleep $EVERY
    CHECK=$((CHECK+1))
done
echo

## If /Incomplete dir. is true then shutdown function.
if [[ "$(ls -A $DIRI)" ]]; then
    tput setaf 1; tput rc
    echo -e "--------------------------------------------------------------\n\
Default time limit reached torrents incomplete!\n\
$(ls -1 $DIRI)\n\
--------------------------------------------------------------" | tee -a $LOG
    haltpc                                      # shutdown function.
fi

## Torrents completed before default? then seed.
tput rc
echo -e "--------------------------------------------------------------\n\
Completed files transferred out at `date +%T`" | tee -a $LOG
echo -n "to directory " | tee -a $LOG
tput setaf 7
echo -e "\"$DIRC\"\n\
--------------------------------------------------------------" | tee -a $LOG
echo -ne "\"$DIRI\""
tput setaf 6
echo -e " is now empty."
DIFF=$((DSET-`date +%s`))                       # default time remaining.
if [ "$DIFF" -le "$SEED" ]; then
    SEED=$DIFF
fi

## Seed time allocation.
if [ "$SEED" -gt "0" ]; then
    echo -e "Torrent residual seed $SEED seconds" >> $LOG
    tput setaf 1
    for i in $(eval echo {$SEED..0}); do        # count down from seed value.
        printf "\r%s""This computer will shut down in: "$i
        tput el
     sleep 1
    done
fi
echo
haltpc                                          # shutdown function.




Powered by ScribeFire.