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 data. Show all posts
Showing posts with label data. Show all posts

What torrents?


#!/bin/bash
# Filename: check_torrents.sh
# Version: 070811
# Author: robz
# This script gives a quick peek and an opportunity to edit, what you have
# active in the Transmission bit torrent client, without loading the program
# itself. It runs from a launcher located in my $HOME/Torrents/Complete/
# directory, the line for the "Command:" box of the launcher being:
# gnome-terminal --title="Check Torrents" -x sh -c "path to/check_torrents.sh"
# Deletions are sent to Trash rather than rm'd, just in case you fcuk up :)

C2="\e[1;32m" C6="\e[1;36m" C7="\e[1;37m"                # Green cyan white.
TSCPT="$0"                                               # Path to this script.
TRASH=$HOME/.local/share/Trash                           # Trash location.
TRNTS=$HOME/.config/transmission/torrents                # Trackers location.
CLMNS=$(($(ls "$TRNTS" | wc -L)+10))                     # Terminal columns.
LINES=$(ls "$TRNTS" | wc -l)                             # Terminal lines.
VRBLS=$(ls "$TRNTS" | nl)                                # Torrent list verbal.
VRBL2="Select number to delete or hit Enter to exit. "   # More verbal.

if [ "$LINES" -eq "0" ]; then                            # Anything in there?
VRBLS="No trackers are loaded."; VRBL2="Hit Enter to exit. "; CLMNS=25
fi

# Escape sequences auto size the terminal window and set the background colour.
echo -ne "\e[8;$((${LINES}+5));${CLMNS}t"; echo -ne "\e[44m""\e[37m""\033[2J"
echo -e $C7"Active torrents $LINES:\n""$C6"; echo "$VRBLS"; echo -e $C2

read -n1 -p "$VRBL2" SEL                                 # Delete or exit.
if [[ "$LINES" -gt "0" && "$SEL" -gt "0" && "$LINES" -ge "$SEL" ]]; then
MVFL="$TRNTS/$(ls "$TRNTS" | sed -n "$SEL"p)"            # Get selection.
INFO="$TRASH/info/$(basename $MVFL).trashinfo"           # Trash info location.
echo "[Trash Info]" > "$INFO"                            # Create Trash info.
echo "Path=$TRNTS/$(basename $MVFL)" >> "$INFO"
echo "DeletionDate=$(date +%FT%T)" >> "$INFO"
mv "$MVFL" "$TRASH/files"                                # Send file to trash.
# Restart terminal and re-list remaining torrent tracker files.
gnome-terminal --geometry=+0+0 --title="Check Torrents" -x sh -c "$TSCPT"
fi

P2P Blocklist tool

#!/bin/bash
# Filename: blocklists.sh
# Version: 170511
# Author: robz
# AFAIK "transmission" can only be configured to download a single blocklist
# automatically. That default, if set, being the level1 blocklist from
# http://update.transmissionbt.com/level1.gz. This script is to auto download
# the latest or extra P2P blocklists to suppliment or replace the default.
# All being well the script will download from the "$URLS" list and create a
# file which "transmisson-gtk" can parse, the old list will then be replaced
# ready for "transmission-gtk" to create a new binery file on startup.
# If this doesn't happen for some reason the existing will be left in place.
# Script can be used on it's own, or uncomment the last line and create a
# custom launcher for the Transmission bittorent client.

# Some reading http://torrentfreak.com/do-p2p-blocklists-keep-you-safe/
# Some suggested urls:
# http://list.iblocklist.com/?list=bt_level1        # General default list.
# http://list.iblocklist.com/?list=bt_level2        # Labs or researchers.
# http://list.iblocklist.com/?list=bt_level3        # The paranoids list.
# http://list.iblocklist.com/?list=bt_bogon         # Unallocated addresses.
# http://list.iblocklist.com/?list=bt_templist      # Suspected bad peers.
# http://list.iblocklist.com/?list=bt_spyware       # Suspected spy/malware.

# Add urls to this $URLS list.
URLS="
http://list.iblocklist.com/?list=bt_level2
http://list.iblocklist.com/?list=bt_level3
http://list.iblocklist.com/?list=bt_bogon
"
TMP="/tmp/blocklists/"                              # Temporary workspace.
LISTS="$HOME/.config/transmission/blocklists"       # Blocklists location.

rm -rf $TMP; mkdir $TMP; cd $TMP                    # Clear the way.
wget --retry-connrefused $URLS                      # Get lists.....persist.
if [ ! $? = 0 ]; then exit $?; fi
cat * > extras.gz                                   # Concatenate the lists.
gunzip -c extras.gz > extras
if [ ! $? = 0 ]; then exit $?; fi
if [[ -s "extras" ]]; then
    sort -u extras -o extras.txt                    # Sort unique to txt file.
else exit $?
fi
rm -f $LISTS/extras*                                # Purge old txt/bin files.
mv -f extras.txt $LISTS/"extras $(date +%d-%b-%R).txt"

#transmission-gtk &                                 # Start bt client?

 

Make executable

#!/bin/bash
# Filename: Exbit-set
# Version: 170411

# Author: robz
# Another right click nautilus-scripts script. This one sets the executable
# bit, handling multiple files and filenames with spaces.

for FILE; do chmod u+x "$FILE"; done

# Brief but useful.


Simple cron backup

#!/bin/bash
# Filename: Backup
# Version: 211010
# Author: robz
# Works with "Back In Time" to backup, log actions and notify when complete.
# Configure "Back In Time" via the GUI and run from a user crontab.
# 00 */6 * * * export DISPLAY=:0 && /home//.scripts/Backup > /dev/null 

# 2>&1

NOW=`date +%A-%H:%M`                                    # Datestamp.
SOUND=$HOME/Audio/2tone.wav
ICON=/usr/share/icons/Humanity/actions/48/document-save.svg

LOGFILE="$HOME/Backup-for-$NOW.log"                     # Log name and path.
OLDLOG="$HOME/Backup-for-*.log"

rm -f $OLDLOG                                           # Delete old logfile.
sync && nice -n 19 \
/usr/bin/backintime --backup-job 2>&1 > $LOGFILE && \   # Do backup n'log.
notify-send -i $ICON "Backup job has completed" & \     # Hey it's done.
/usr/bin/canberra-gtk-play --volume 6 -f $SOUND         # I said, IT'S DONE!


Powered by ScribeFire.

Media file exif data extraction

#!/bin/bash
# Filename: EXIFdata
# Author: robz
# Version: 230910
# Get media file atributes, works with audio, video and photo.
# You'll need this "libimage-exiftool-perl" and "most"
# Put this script in /home/<user>/.gnome2/nautilus-scripts
# Right click on the file(s) you want data from, goto Scripts > EXIFdata.
# The "-r" switch allows to recurse through a selected directory.
# Check out "man exiftool" for full explanation of switches (extensive).

QUOTED=$(echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" |\
    awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
gnome-terminal --title="EXIF data extractor" -x bash -c\
    "exiftool -r -m $QUOTED | most"

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.