Code Dump: channeldown.sh

Building on youtube.sh, this downloads an entire youtube channel. Usefull for marathon viewing sessions.

#!/bin/bash if [ "x$1" = "x" ] then echo channeldown "(username)" exit fi if [ ! "x$2" = "x" ] then MAX=$2 else MAX=100 fi USER=$1 i=1 while [ $i -lt "$MAX" ] do wget http://gdata.youtube.com/feeds/api/users/$USER/uploads\?start-index="$i"\&max-results=50 -O $USER.$i.raw let "i+=50" done #results=($(cat $USER*raw | sed 's/.*\(http:\/\/www.youtube.com\/watch?v=.\{11\}\).*/\1/g;/^http/!s/.*//g;/watch/!s/.*//g' | sort | uniq)) results=($(cat $USER*raw | sed 's/http/\nhttp/g' | grep 'api/videos' | sed 's/.*videos\///g;s/[<\/].*//g'|sort | uniq)) echo $results mkdir /downloads/watch/misc/$USER for X in ${results[@]} do X="http://youtube.com/watch?v=$X" echo $X >> $USER.log youtube-dl -o "/downloads/watch/misc/$USER/%(upload_date)s.%(stitle)s.%(ext)s" "$X" done rm $USER*raw

Code Dump: youtube.sh

Downloads youtube videos using youtube-dl. I built it to download multiple videos in a row. Put each url in a pair of single quotes.

“`bash
#!/bin/bash SETDIR=”/downloads/watch/misc” DIRFLAG=0 for ARG in $* do ARG=”$(echo “$ARG” | sed ‘s/feature=[a-z_+]*&//’)” # http://www.youtube.com/watch?feature=player_embedded&v=qeK0KmtYNaA # http://www.youtube.com/watch?v=kV832rfjcas&feature=related echo “$ARG” if [ x$ARG = x ] then exit elif [ x$ARG = “x-d” ] then DIRFLAG=1 elif [ $DIRFLAG = 1 ] then DIRFLAG=0 SETDIR=$ARG else echo “$SETDIR $ARG” youtube-dl -w -o “$SETDIR/%(title)s.%(ext)s” –max-quality=22 “$ARG” fi done
“`

Code Dump: Brighty

For some reason, on my Acer Aspire laptop, Ubuntu doesn’t seem to respond to the brightness settings, but this script works. It’s probably not terribly safe, but it add a good 20-30 minutes of battery life when I set it to the lowest setting I can see.

“`bash
#!/bin/bash function helpa { echo brighty [ 1 – 976 ] } if [ x$1 = x ] then helpa elif [ $1 -gt 976 ] then helpa else echo $1 | sudo tee /sys/class/backlight/intel_backlight/brightness fi
“`

Code Dump: rand.sh

Generates random strings. I got tired of having to go to [random.org](http://random.org “Random.org”), and this takes like 2 seconds.

VERSION=4
NUM=0
LEN=0
MODE=0
LN=0
ALLOW=""
for Y in $@
do
        if [ $Y = "-n" ]
        then
                MODE=1
                ALLOW=$ALLOW"0-9"
        elif [ $Y = "-s" ]
        then
                MODE=5
                ALLOW=$ALLOW'!@#$%^&*()-_=+'
        elif [ $Y = "-l" ]
        then
                MODE=2
                ALLOW=$ALLOW"a-z"
        elif [ $Y = "-u" ]
        then
                MODE=3
                ALLOW=$ALLOW"A-Z"
        elif [ $Y = "-c" ]
        then
                ALLOW="0-9A-F"
                LEN=6
        elif [ $Y = "-X" ]
        then
                ALLOW='0-9A-Fa-f!@#$%^&**()-_=+'
        elif [[ "$Y" =~ ^[0-9]+$ ]] && [[ LEN -eq 0 ]]
        then
                LEN=$Y
        elif [[ "$Y" =~ ^[0-9]+$ ]] && [[ LEN -gt 0 ]]
        then
                NUM=$Y
        elif [ $Y = "-b" ]
        then
                MODE=0
        elif [ $Y = "-N" ]
        then
                LN=1
  elif [ $Y = "-D" ]
  then
    echo $(curl -s "http://www.dinopass.com/password/simple")
    exit
        else
                echo "rand [arg] [length] [number]"
                echo "Arguements"
                echo -e "-b\tbasic\n-X\tcomplex\n-n\tnumber\n-l\tlowercase\n-u\tuppercase\n-s\tsymbols\n-c\tcolor\n-D\tdinopass"
                exit
        fi
done
if [ $LEN -eq 0 ]
then
        LEN=10
fi
if [ $NUM -eq 0 ]
then
        NUM=1
fi
if [ x$ALLOW = "x" ]
then
        ALLOW="A-Za-z0-9"
fi
X=0
while [ $X -lt $NUM ]
do
        if [ $LN -eq 1 ]
        then
                printf "%0${#NUM}g: " "$(($X+1))"
        fi
        </dev/urandom tr -dc $ALLOW | head -c$LEN;echo
        let "X++"
done

Code Dump: Core.sh and Startconky.sh

Used to randomly select from several wallpapers and apply a specific conky theme to it.

core.sh

“`bash
#!/bin/sh TOTAL=$(ls /home/michael/.conky/ | grep png | wc -l) if [ “x$1” != “x” ] then if [ $1 -gt -1 ] && [ $1 -lt $(ls /home/michael/.conky/| grep png | wc -l) ] then URAND=0 RANDER=$1 else echo INVALID NUMBER URAND=1 fi else URAND=1 fi if [ $URAND = 1 ] then RANDER=$(echo “$(/home/michael/apps/rand -n) % $TOTAL” | bc) fi echo $RANDER gsettings set org.gnome.desktop.background picture-uri file:///home/michael/.conky/core$RANDER.png cp /home/michael/.conkyrc$RANDER /home/michael/.conkyrc
“`

startconky.sh

“`bash
cat startconky #!/bin/bash while [ true ] do /home/michael/apps/core.sh sleep 30; conky & sleep 30m sudo killall conky done
“`

Rsyslog – Log only to first match.

Giving the tilde (~) as an action causes that message to be discarded. There’s also the ampersand syntax – if a line starts with & it is considered an additional action for the previous line’s selector. So something like this:
> mail.* /var/log/mail.log
> & ~
>
> kern.* /var/log/kern.log
> & ~
>
> *.* /var/log/catchall

[via This Forum Post](http://kb.monitorware.com/logging-first-match-t8601.html )