You are not logged in.

#601 2009-10-24 06:14:24

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 997
Website

Re: Post your handy self made command line utilities

A script that draws the Hypnotoad in terminal:

#!/usr/bin/perl

# script by karabaja4
# mail: karabaja4@archlinux.us

my $blackFG_yellowBG = "\e[30;43m";
my $blackFG_redBG = "\e[30;41m";
my $blackFG_purpleBG = "\e[30;45m";

my $yellowFG_blackBG = "\e[1;33;40m";
my $yellowFG_redBG = "\e[1;33;41m";

my $redFG_yellowBG = "\e[31;43m";

my $purpleFG_yellowBG = "\e[35;43m";
my $purpleFG_blueBG = "\e[1;35;44m";

my $end = "\e[0m";

system("clear");

print "

               ${blackFG_yellowBG},'${blackFG_redBG}`${blackFG_yellowBG}`.._${end}   ${blackFG_yellowBG},'${blackFG_redBG}`${end}${blackFG_yellowBG}`.${end}
              ${blackFG_yellowBG}:${blackFG_redBG},${yellowFG_blackBG}--.${end}${blackFG_redBG}_${blackFG_yellowBG}:)\\,:${blackFG_redBG},${yellowFG_blackBG}._,${end}${yellowFG_redBG}.${end}${blackFG_yellowBG}:${end}
              ${blackFG_yellowBG}:`-${yellowFG_blackBG}-${end}${blackFG_yellowBG},${blackFG_yellowBG}''${end}${redFG_yellowBG}@@\@${end}${blackFG_yellowBG}:`.${yellowFG_redBG}.${end}${blackFG_yellowBG}.';\\${end}        All Glory to
               ${blackFG_yellowBG}`,'${end}${redFG_yellowBG}@@@@@@\@${end}${blackFG_yellowBG}`---'${redFG_yellowBG}@\@${end}${blackFG_yellowBG}`.${end}     the HYPNOTOAD!
               ${blackFG_yellowBG}/${redFG_yellowBG}@@@@@@@@@@@@@@@@\@${end}${blackFG_yellowBG}:${end}
              ${blackFG_yellowBG}/${redFG_yellowBG}@@@@@@@@@@@@@@@@@@\@${end}${blackFG_yellowBG}\\${end}
            ${blackFG_yellowBG},'${redFG_yellowBG}@@@@@@@@@@@@@@@@@@@@\@${end}${purpleFG_yellowBG}:\\${end}${blackFG_yellowBG}.___,-.${end}
           ${blackFG_yellowBG}`...,---'``````-..._${redFG_yellowBG}@@@\@${end}${blackFG_purpleBG}|:${end}${redFG_yellowBG}@@@@@@\@${end}${blackFG_yellowBG}\\${end}
             ${blackFG_yellowBG}(                 )${end}${redFG_yellowBG}@@\@${end}${blackFG_purpleBG};:${end}${redFG_yellowBG}@@@\@)@@\@${end}${blackFG_yellowBG}\\${end}  ${blackFG_yellowBG}_,-.${end}
              ${blackFG_yellowBG}`.              (${end}${redFG_yellowBG}@@\@${end}${blackFG_purpleBG}//${end}${redFG_yellowBG}@@@@@@@@@\@${end}${blackFG_yellowBG}`'${end}${redFG_yellowBG}@@@\@${end}${blackFG_yellowBG}\\${end}
               ${blackFG_yellowBG}:               `.${end}${blackFG_purpleBG}//${end}${redFG_yellowBG}@@)@@@@@@)@@@@@,\@${end}${blackFG_yellowBG};${end}
               ${blackFG_purpleBG}|`${purpleFG_yellowBG}.${blackFG_yellowBG}            ${end}${purpleFG_yellowBG}_${end}${purpleFG_yellowBG},${blackFG_purpleBG}'/${end}${redFG_yellowBG}@@@@@@@)@@@@)@,'\@${end}${blackFG_yellowBG},'${end}
               ${blackFG_yellowBG}:${end}${blackFG_purpleBG}`.`${end}${purpleFG_yellowBG}-..____..=${end}${blackFG_purpleBG}:.-${end}${blackFG_yellowBG}':${end}${redFG_yellowBG}@@@@@.@@@@\@_,@@,'${end}
              ${redFG_yellowBG},'${end}${blackFG_yellowBG}\\ ${end}${blackFG_purpleBG}``--....${end}${purpleFG_blueBG}-)='${end}${blackFG_yellowBG}    `.${end}${redFG_yellowBG}_,@\@${end}${blackFG_yellowBG}\\${end}    ${redFG_yellowBG})@@\@'``._${end}
             ${redFG_yellowBG}/\@${end}${redFG_yellowBG}_${end}${redFG_yellowBG}\@${end}${blackFG_yellowBG}`.${end}${blackFG_yellowBG}       ${end}${blackFG_redBG}(@)${end}${blackFG_yellowBG}      /${end}${redFG_yellowBG}@@@@\@${end}${blackFG_yellowBG})${end}  ${redFG_yellowBG}; / \\ \\`-.'${end}
            ${redFG_yellowBG}(@@\@${end}${redFG_yellowBG}`-:${end}${blackFG_yellowBG}`.     ${end}${blackFG_yellowBG}`' ___..'${end}${redFG_yellowBG}@\@${end}${blackFG_yellowBG}_,-'${end}   ${redFG_yellowBG}|/${end}   ${redFG_yellowBG}`.)${end}
             ${redFG_yellowBG}`-. `.`.${end}${blackFG_yellowBG}``-----``--${end}${redFG_yellowBG},@\@.'${end}
               ${redFG_yellowBG}|/`.\\`'${end}        ${redFG_yellowBG},',');${end}
                   ${redFG_yellowBG}`${end}         ${redFG_yellowBG}(/${end}  ${redFG_yellowBG}(/${end}


";

Offline

#602 2009-10-24 09:27:32

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Post your handy self made command line utilities

lol, love the hypnotoad

This script I got the idea from VictorVictorVictor's plasma config backup script.  I found too that at times the plasma configurations go bad at times.  This backups and also restores from a provided list.  lolilolicon helped me learn how to create the list:

plasmabak b|r
#!/bin/bash
# plasmabak - backup and restore local plasma config

# text color variables
bldylw='\e[1;33m' # yellow
bldblu='\e[1;34m' # blue
bldred='\e[1;31m' # red
bldwht='\e[1;37m' # white
txtrst='\e[0m'    # text reset

backdir=/root/backup/kde4-plasma-rcs
userdir=/home/todd
plasmarcs=($(find "$userdir"/.kde4/share/config -type f -name "plasma*"))
bkpplasmarcs=($(find "$backdir" -type f -name "plasma*"))
date=$(date +%F)

# Display usage if full argument isn't given
if [[ -z "$@" ]]; then
  echo " ${0##*/} b|r - backup or restore plasma configurations"
  exit
fi

# Check if the directory exists and user has access to it
if [[ -n $(ls "$backdir" 2>&1 | grep denied) ]]; then
  echo -e "${bldred}*${txtrst} User doesn't have access to directory"
  exit
  else
  if [[ ! -d "$backdir" ]]; then
    mkdir "$backdir"
    echo -e "${bldblu}*${txtrst} KDE 4 plasma config backup directory doesn't exist.  Created."
  fi
fi

# Delete backups older than two months
if [[ -n "$(find "$backdir" -mtime +60)" ]]; then
  find "$backdir" -mtime +60 -exec rm {} \;
  echo -e "${bldblu}*${txtrst} Configurations older than two months deleted"
fi

case $1 in
  b | backup )  tar -czpf "$backdir"/plasmarcs-"$date".tar.gz ${plasmarcs[@]}
                echo "${bldblu}*${txtrst} plasma configurations backed up."
                ;;
  r | restore ) for((i=0;i<${#bkpplasmarcs[@]};i++)) ; do
                  echo -e " ${bldwht}${i}) ${bkpplasmarcs[$i]##*/}${txtrst}"
                done
                echo -n "Choose the plasma configuration to restore: "
                read restore
                selection="${bkpplasmarcs[$restore]}"
                tar -xvf "$selection" -C /
                echo -e " ${bldwht}*${txtrst} Restored plasma configs: ${bldwht}${bkpplasmarcs[$restore]##*/}${txtrst}"
                ;;
  * )           echo -e " ${bldwht}*${txtrst} Use 'plasmabak b' to backup and 'plasmabak r' to restore"
esac

Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#603 2009-10-24 22:36:01

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

Didn't read through all 25 previous pages, so my apologies if any of this is a repost.

Controls my WinXP VBox. I mostly use the start/stop over ssh when I'm trying to get at it from school.

#! /bin/bash

VBOX_HOST=WinXP
REMOTE_HOST=localhost
REMOTE_PORT=3390

if [ "$1" == "start" ]; then
    if [ -z `pgrep VBoxHeadless` ]; then
        VBoxHeadless -startvm "$VBOX_HOST" &
    else
        echo "ERROR: VBox '$VBOX_HOST' is running."
        exit 1
    fi
    disown
elif [ "$1" == "stop" ]; then
    if [ -z `pgrep VBoxHeadless` ]; then
        echo "ERROR: VBox '$VBOX_HOST' is not running."
        exit 1
    else
        VBoxManage controlvm "$VBOX_HOST" poweroff
    fi
elif [ "$1" == "connect" ]; then
    echo -n "[vbox] password for `id -nu`: "
    STTY_ORIG=`stty -g`
    stty -echo
    read PASSWORD
    echo
    stty $STTY_ORIG

    if [ -z `pgrep VBoxHeadless` ]; then
        VBoxHeadless -startvm "$VBOX_HOST" &
        sleep 5
    fi
    rdesktop -p"$PASSWORD" $REMOTE_HOST:$REMOTE_PORT
    disown
    exit 0
else
    echo "USAGE: vbox start|stop|connect"
    echo
    echo "Host: $VBOX_HOST @ $REMOTE_HOST:$REMOTE_PORT"
    echo "Status: `VBoxManage showvminfo $VBOX_HOST | grep State | cut -d" " -f12-`"
fi

Push/pull all git repos. Wrote it for my brother who often works from multiple computers.

#! /bin/bash

function usage {
    echo "USAGE: git-all status|push|pull [origin <remote>]"
    echo ""
    echo "git-all will push or pull all git repositories found one level deeper than your current location."
    exit
}

if [ "$1" == "push" ] || [ "$1" == "pull" ]; then
    FOUND=0
    SUCCESS=0
    FAIL=0

    BASEDIR=`pwd`

    for d in `find . -maxdepth 1 -type d`; do
        d=`basename $d`
        if [ -d ${BASEDIR}/${d}/.git ]; then
            FOUND=$(($FOUND + 1))
            cd ${BASEDIR}/${d}
            git $1 $2 $3

            if [ $? -eq 0 ]; then
                SUCCESS=$(($SUCCESS + 1))
            else
                FAIL=$(($FAIL + 1))
                echo "git-all: Error while ${1}ing repo `pwd`"
            fi
            echo ""
        fi
    done

    echo "git-all-${1}: $FOUND repositories found. $SUCCESS repositories affected."
    if [ $FAIL -gt 0 ]; then
        echo "git-all-${1}: $FAIL errors occurred. Check console log for details."
    fi
    
    exit 0
fi

if [ "$1" == "status" ]; then

    BASEDIR=`pwd`

    for d in `find . -maxdepth 1 -type d`; do
        d=`echo $d | sed -e 's/\.\///g'`
        if [ -d ${BASEDIR}/${d}/.git ]; then
            cd ${BASEDIR}/${d}
            if [ `git status | wc -l` -gt 2 ]; then
                echo "Repository '$d' has outstanding changes."
            fi
        fi
    done
    
    exit 0
fi

usage

Get the daily New York Times crossword puzzle! Subscription required...

#!/bin/bash

usage() {
    echo "Usage: getDailyCrossword.sh [date]"
    echo "   date can be in mm/dd/yy form or a valid token: yesterday|today|tomorrow"
    exit 0
}

case $1 in
  today|tomorrow|yesterday )
    DATESTRING=`date --date=$1 +%b%d%y`
  ;;
  *[[:digit:]]/*[[:digit:]]/*[[:digit:]] )
    DATESTRING=`date --date=$1 +%b%d%y`
  ;;
  *)
    usage
  ;;    
esac

COOKIE_JAR=cookies.tmp
WEB_PAGE=tmp.html
LOGIN_PAGE=http://www.nytimes.com/auth/login
USERNAME="USERID=<userid>"
PASSWORD="PASSWORD=<password>"
XWORD_URL="http://select.nytimes.com/premium/xword/$DATESTRING.puz"
HIDDEN_FIELDS="is_continue=true&URI=http://&OQ=&OP=Submit2=Log%20In"
OUTPUT_DIR="$HOME/Desktop"

echo -n "Logging in... "
curl --silent --cookie-jar $COOKIE_JAR \
    --output $WEB_PAGE \
    $LOGIN_PAGE

curl --silent --cookie $COOKIE_JAR --cookie-jar $COOKIE_JAR \
    --data "$HIDDEN_FIELDS&$USERNAME&$PASSWORD" \
    --output $WEB_PAGE \
    --location \
    $LOGIN_PAGE

# Make sure we're logged in
if [[ `cat $COOKIE_JAR | wc -l` -lt 7 ]]; then
    echo "failed!"
    exit 1
else
    echo "success!"
fi

# Get the puzzle
echo -n "Getting puzzle for $1... "
curl --silent --cookie $COOKIE_JAR --cookie-jar $COOKIE_JAR \
    --output $OUTPUT_DIR/$DATESTRING.puz \
    $XWORD_URL

#What type of file is our result?
RESULT=`file $OUTPUT_DIR/$DATESTRING.puz | cut -d\  -f2-`

case "$RESULT" in
  "data")
    echo "success!"
    rm $WEB_PAGE
    rm $COOKIE_JAR
  ;;
  "HTML document text")
    echo "error! (Puzzle not yet available?)"
    if [[ -e $OUTPUT_DIR/$DATESTRING.puz ]]; then
        rm $OUTPUT_DIR/$DATESTRING.puz
    fi
    exit 1
  ;;
esac

Cronjob to keep my DynDNS account alive (since my IP rarely changes):

#!/bin/bash

USERNAME=<username>
PASSWORD=<password>
IP=`curl http://www.whatismyip.com/automation/n09230945.asp`

curl -v -k "http://$USERNAME:$PASSWORD@members.dyndns.org/nic/update?hostname=notrly.mine.nu&myip=$IP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"

Convert a manpage to a pdf. Uses uhhh ps2pdf, which was in Ubuntu and, hrmm... I'm sure it's around here somewhere...

man2pdf() {
    if [[ -z $1 ]]; then
        echo "USAGE: man2pdf [manpage]"
    else
        if [[ `find /usr/share/man -name $1\* | wc -l` -gt 0 ]]; then
                out=/tmp/$1.pdf
                if [[ ! -e $out ]]; then
                        man -t $1 | ps2pdf - > $out
                fi
                if [[ -e $out ]]; then
                        /usr/bin/evince $out
                fi
        else
                echo "ERROR: manpage \"$1\" not found."
        fi
    fi
}

Looking back, some of these are in need of a rewrite.

Offline

#604 2009-10-26 00:18:11

sirmacik
Member
From: Poland/Warsaw
Registered: 2008-06-17
Posts: 65
Website

Re: Post your handy self made command line utilities

Hi!
This is my handy script for entering i686 chroot. It has to be run as root.

#!/bin/sh
# --{{{ Settings 
CHPATH="/media/arch_i686" # chroot mountpoint
ROOTPART="/dev/sda1" # chroot root partition 
# --}}}

check(){
    if [ "$?" == "0" ]; then
        echo "      [OK!]"
    else
        echo "      [ERROR] Can't mount or already mounted!"
    fi
}
read -p "Mount partitions and prepare internet connection? [Y/n] " answer
if [ "$answer" = "n" ]; then 
    echo "No!"
else
    echo "Yes!"
    echo "Mounting..."
    read -p "Mount root? [Y/n] " mntroot
    if [ "$mntroot" = "n" ]; then
        echo "        No!"
    else
        echo -e "      /...\c"
        mount $ROOTPART $CHPATH
        check
    fi
    echo -e "      /proc...\c"
    mount -t proc none $CHPATH/proc
    check
    echo -e "      /dev...\c"
    mount -o bind /dev $CHPATH/dev 
    check
    echo -e "      /tmp...\c"
    mount --bind /tmp $CHPATH/tmp 
    check
    echo -e "      /sys...\c"
    mount -t sysfs none $CHPATH/sys
    check
    echo -e "      /home...\c"
    mount --bind /home $CHPATH/home
    check 
    
    echo "Copying resolv.conf..."
    cp -L /etc/resolv.conf $CHPATH/etc/
fi
echo "Entering chroot environment..."
chroot $CHPATH /bin/bash
read -p "Unmount partitions? [Y/n] " mount_answer
if [ "$mount_answer" = "n" ]; then
    echo "No!"
    exit 0
else
    echo "Unmounting..."
    echo -e "      /proc...\c"
    umount $CHPATH/proc
    check
    echo -e "      /dev...\c"
    umount $CHPATH/dev
    check
    echo -e "      /tmp...\c"
    umount $CHPATH/tmp
    check
    echo -e "      /sys...\c"
    umount $CHPATH/sys
    check
    echo -e "      /home...\c"
    umount $CHPATH/home
    check
    read -p "Unmount root? [Y/n] " root_answer
    if [ "$root_answer" = "n" ]; then
        echo "No!"
    else
        echo -e "      /...\c"
        umount "$CHPATH"
        check
    fi
fi

Last edited by sirmacik (2009-10-26 00:19:52)

Offline

#605 2009-10-26 04:39:51

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Why not use mkarchroot?

Offline

#606 2009-10-26 09:28:41

sirmacik
Member
From: Poland/Warsaw
Registered: 2008-06-17
Posts: 65
Website

Re: Post your handy self made command line utilities

Daenyth wrote:

Why not use mkarchroot?

Oh, I didn't know that this script exists. ;x
For me it was faster to write my own, than search for some solution like mkarchroot, but I'll get more information about it. Thanks Daenyth!

Offline

#607 2009-10-26 09:58:53

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Post your handy self made command line utilities

pacman -S .mkarchroot

?


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#608 2009-10-26 10:24:56

sirmacik
Member
From: Poland/Warsaw
Registered: 2008-06-17
Posts: 65
Website

Re: Post your handy self made command line utilities

Gen2ly wrote:

pacman -S .mkarchroot

?

Rather pacman -S extra/devtools

Offline

#609 2009-10-26 20:58:15

lswest
Member
From: Munich, Germany
Registered: 2008-06-14
Posts: 456
Website

Re: Post your handy self made command line utilities

Below is just a small script I use to throw together what I call a "catalog" of my music, using the information from the MP3 tags.  It uses the eyeD3 module, so you'll need to install that (it's in the AUR though).  Basically it just compiles a formatted list of each song.  You could probably easily edit it to display just artists, etc., but I found this to be the most useful.  In case you're wondering why I would ever need this, I get tired of trying to list off a collection of artists if someone asks me what music I listen to, or something like that, so now I can just send them the list of songs.  I'm fairly certain I commented the script fairly well, and it should work fine for any linux-based machine (no idea about windows, since you'd have to install eyeD3).  Also, it makes a list of all your files in musicList.txt, so you can set the script to automatically delete it/skip that step if you'd like, but I find it useful to have around for debugging purposes.

*EDIT* Word of warning: The script isn't really complete, since it can't create the catalog of any kind of file besides mp3.  I don't know of a module for python that can read those tags, so for the time being it will find the files, but skip them in the catalog (all my music has been converted to mp3 anyway).

#/usr/bin/env python
# Script to create a "catalog" of music on a computer
import os
import sys
import optparse
import eyeD3


def main():
    reload(sys)
    sys.setdefaultencoding("latin-1")
    usage="usage: %prog [options] args"
    # Configure the command-line options to take in the location of the music directory, the output file (intermediary list of filepaths for debug purposes), and the catalog's location (end file)
    p=optparse.OptionParser()
    p.add_option('--origin', '-o', help="The location of the directory to search.", default=os.path.join(os.path.expanduser('~'), "Music"))
    p.add_option('--output', '-f', help="The location of the output file.", default=os.path.join(os.path.expanduser('~'),"musicList.txt"))
    p.add_option('--catalog', '-c', help="The location of the end catalog of artist, title and album", default=os.path.join(os.path.expanduser('~'),"Catalog.txt"))
    options, arguments=p.parse_args()
    print options.origin
    # Open what will become the intermediary file for writing.
    ff=open(options.output, "wt")
    #Recursively follow the filetree of the music folder, and write the filepath to any audio file out to the intermediary file.
    for root, dirs, files in os.walk(options.origin, followlinks=True):
         for infile in [f for f in files if f.endswith(('.mp3', '.MP3','.wma','.WMA','.m4a','.M4A'))]:
              ff.write(os.path.abspath(os.path.join(root,infile)))
              ff.write('\n')
    ff.close() # close file
    tags(options.output,options.catalog) # move on to pulling the ID3 tag info from the mp3's using the debug file.

def tags(file,catalogFile):
    catalog=[] #empty list which will contain the tuples of song info
    nonMP3=[] # a list of all non-mp3 files that need to have their info pulled differently.
    tag=eyeD3.Tag() # initiate the tag instance of the eyeD3 module
    ff=open(file, "r") # open the debug file as read-only.
    fh=open(catalogFile,"wt")
    for x in ff: # for each file path, strip off any extra new-line characters, then check to see if it's an mp3.  If so, store the ID3 tag info in the tuple and list, otherwise add the filepath to the non-mp3 list.
        x=x.strip()
        if x.endswith('.mp3'):
            try:
                tag.link(x)
            except:
                print "FAILED -" + x.strip()
            songInfo=[tag.getTitle(), tag.getArtist(), tag.getAlbum()] # add the info into the tuple
            catalog.append(songInfo) # add tuple to list
        else:
            nonMP3.append(x.strip()) # add filepath to nonMP3 list.
    finalCatalog=sorted(catalog, key=lambda (x,y,z):(y,z)) # Attempt to sort the lists of tuples by second value of tuples (artist)
    for x in finalCatalog: # print out the info as Title - Artist (Album).
        fh.write('{0:45} - {1:20} {2:20}'.format(x[0],x[1],"("+x[2]+")")) # write the song, artist and album information with a set value of characters, in order to keep things neat.
        fh.write("\n")
        


if __name__=='__main__':
        main()

Last edited by lswest (2009-10-26 21:01:09)


Lswest <- the first letter of my username is a lowercase "L".
"...the Linux philosophy is "laugh in the face of danger". Oops. Wrong one. "Do it yourself". That's it." - Linus Torvalds

Offline

#610 2009-10-26 22:43:44

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

Re: Post your handy self made command line utilities

karabaja4 wrote:

A script that draws the Hypnotoad in terminal:

#!/usr/bin/perl

# script by karabaja4
# mail: karabaja4@archlinux.us

my $blackFG_yellowBG = "\e[30;43m";
my $blackFG_redBG = "\e[30;41m";
my $blackFG_purpleBG = "\e[30;45m";

my $yellowFG_blackBG = "\e[1;33;40m";
my $yellowFG_redBG = "\e[1;33;41m";

my $redFG_yellowBG = "\e[31;43m";

my $purpleFG_yellowBG = "\e[35;43m";
my $purpleFG_blueBG = "\e[1;35;44m";

my $end = "\e[0m";

system("clear");

print "

               ${blackFG_yellowBG},'${blackFG_redBG}`${blackFG_yellowBG}`.._${end}   ${blackFG_yellowBG},'${blackFG_redBG}`${end}${blackFG_yellowBG}`.${end}
              ${blackFG_yellowBG}:${blackFG_redBG},${yellowFG_blackBG}--.${end}${blackFG_redBG}_${blackFG_yellowBG}:)\\,:${blackFG_redBG},${yellowFG_blackBG}._,${end}${yellowFG_redBG}.${end}${blackFG_yellowBG}:${end}
              ${blackFG_yellowBG}:`-${yellowFG_blackBG}-${end}${blackFG_yellowBG},${blackFG_yellowBG}''${end}${redFG_yellowBG}@@\@${end}${blackFG_yellowBG}:`.${yellowFG_redBG}.${end}${blackFG_yellowBG}.';\\${end}        All Glory to
               ${blackFG_yellowBG}`,'${end}${redFG_yellowBG}@@@@@@\@${end}${blackFG_yellowBG}`---'${redFG_yellowBG}@\@${end}${blackFG_yellowBG}`.${end}     the HYPNOTOAD!
               ${blackFG_yellowBG}/${redFG_yellowBG}@@@@@@@@@@@@@@@@\@${end}${blackFG_yellowBG}:${end}
              ${blackFG_yellowBG}/${redFG_yellowBG}@@@@@@@@@@@@@@@@@@\@${end}${blackFG_yellowBG}\\${end}
            ${blackFG_yellowBG},'${redFG_yellowBG}@@@@@@@@@@@@@@@@@@@@\@${end}${purpleFG_yellowBG}:\\${end}${blackFG_yellowBG}.___,-.${end}
           ${blackFG_yellowBG}`...,---'``````-..._${redFG_yellowBG}@@@\@${end}${blackFG_purpleBG}|:${end}${redFG_yellowBG}@@@@@@\@${end}${blackFG_yellowBG}\\${end}
             ${blackFG_yellowBG}(                 )${end}${redFG_yellowBG}@@\@${end}${blackFG_purpleBG};:${end}${redFG_yellowBG}@@@\@)@@\@${end}${blackFG_yellowBG}\\${end}  ${blackFG_yellowBG}_,-.${end}
              ${blackFG_yellowBG}`.              (${end}${redFG_yellowBG}@@\@${end}${blackFG_purpleBG}//${end}${redFG_yellowBG}@@@@@@@@@\@${end}${blackFG_yellowBG}`'${end}${redFG_yellowBG}@@@\@${end}${blackFG_yellowBG}\\${end}
               ${blackFG_yellowBG}:               `.${end}${blackFG_purpleBG}//${end}${redFG_yellowBG}@@)@@@@@@)@@@@@,\@${end}${blackFG_yellowBG};${end}
               ${blackFG_purpleBG}|`${purpleFG_yellowBG}.${blackFG_yellowBG}            ${end}${purpleFG_yellowBG}_${end}${purpleFG_yellowBG},${blackFG_purpleBG}'/${end}${redFG_yellowBG}@@@@@@@)@@@@)@,'\@${end}${blackFG_yellowBG},'${end}
               ${blackFG_yellowBG}:${end}${blackFG_purpleBG}`.`${end}${purpleFG_yellowBG}-..____..=${end}${blackFG_purpleBG}:.-${end}${blackFG_yellowBG}':${end}${redFG_yellowBG}@@@@@.@@@@\@_,@@,'${end}
              ${redFG_yellowBG},'${end}${blackFG_yellowBG}\\ ${end}${blackFG_purpleBG}``--....${end}${purpleFG_blueBG}-)='${end}${blackFG_yellowBG}    `.${end}${redFG_yellowBG}_,@\@${end}${blackFG_yellowBG}\\${end}    ${redFG_yellowBG})@@\@'``._${end}
             ${redFG_yellowBG}/\@${end}${redFG_yellowBG}_${end}${redFG_yellowBG}\@${end}${blackFG_yellowBG}`.${end}${blackFG_yellowBG}       ${end}${blackFG_redBG}(@)${end}${blackFG_yellowBG}      /${end}${redFG_yellowBG}@@@@\@${end}${blackFG_yellowBG})${end}  ${redFG_yellowBG}; / \\ \\`-.'${end}
            ${redFG_yellowBG}(@@\@${end}${redFG_yellowBG}`-:${end}${blackFG_yellowBG}`.     ${end}${blackFG_yellowBG}`' ___..'${end}${redFG_yellowBG}@\@${end}${blackFG_yellowBG}_,-'${end}   ${redFG_yellowBG}|/${end}   ${redFG_yellowBG}`.)${end}
             ${redFG_yellowBG}`-. `.`.${end}${blackFG_yellowBG}``-----``--${end}${redFG_yellowBG},@\@.'${end}
               ${redFG_yellowBG}|/`.\\`'${end}        ${redFG_yellowBG},',');${end}
                   ${redFG_yellowBG}`${end}         ${redFG_yellowBG}(/${end}  ${redFG_yellowBG}(/${end}


";

What the fuck is th-ALL GLORY TO THE HYPNOTOAD.

Offline

#611 2009-10-28 01:57:58

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

tac /home/Daenyth/.mpd/mpd.log | while read n; do echo ${n%/*}; done | uniq | head

This will give you a list changed directories in your mpd db, most recent at the top.

Offline

#612 2009-10-28 02:14:44

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

karabaja4 wrote:

A script that draws the Hypnotoad in terminal:

Please make this use tput to animate it smile

Offline

#613 2009-10-28 03:41:30

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Post your handy self made command line utilities

Daenyth wrote:
tac /home/Daenyth/.mpd/mpd.log | while read n; do echo ${n%/*}; done | uniq | head

This will give you a list changed directories in your mpd db, most recent at the top.

» tac /home/scp1/.mpd.log | while read n; do echo ${n%/*}; done | uniq | head 
Oct 28 05:36 : avahi: Failed to create client: Daemon not running
Oct 27 22:20 : avahi: Failed to create client: Daemon not running
bfe6d000-bfe6f000 rw-p 00000000 00:00 0
bfe4f000-bfe6d000 rwxp 00000000 00:00 0          [stack]
b7843000-b7844000 rwxp 0001c000 08:01 288018     /lib
b7842000-b7843000 r-xp 0001b000 08:01 288018     /lib
b7826000-b7842000 r-xp 00000000 08:01 288018     /lib
b7825000-b7826000 r-xp 00000000 00:00 0          [vdso]
b7810000-b7811000 rwxp 00000000 00:00 0
b780f000-b7810000 rwxp 0000a000 08:01 490073     /usr/lib

MPD is running...

Offline

#614 2009-10-28 04:25:02

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Odd. Where are those errors coming from? Looks like it's the contents of your mpd.log file. Do you rotate it often? Any crashes lately? Try adding something and running mpc update.

Offline

#615 2009-10-28 16:49:46

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Post your handy self made command line utilities

I recently broke the default playlist size limit of mpd (16000?), and thought something was wrong with python-mpd or my netcat script, so thinking of the other mpd.db scripts in this thread I wrote a script to sort the database to an m3u playlist.

awk 'BEGIN {RS="key:"; FS="\n"} { i=0; while (i++<=NF) { if ( $i ~ /^file:/ ) { file=substr($i,7); }; if ($i ~ /^Album:/) {album=substr($i,8) }; if ( $i ~ /^Artist:/) {artist=substr($i,9) }; if ( $i ~ /^Track:/) { track=substr($i,8) }; if ( $i ~ /^Title:/) { title=substr($i,8) }; }; if ( file != "" ) { print track"\t"album"\t"file"\t"title }; };' ~/.mpd/mpd.db | sort -f -k3,3 | sort -f -s -k4,4 | sort -n -f -s -k1,1 | sort -f -s -k2,2 | cut -f 3 > $(date '+%Y-%M-%d').m3u

I don't sort by artist, but it should be easy to add. The sort pipes go from least significant to most (this works thanks to sort -s). In this case: [filename, title], track, album. The first field must be numeric (track) for sort to work numerically (i.e. you can't sort numerically on fields above 1 due to a coreutils bug). If you add an artist field note that the filename field repeats in cut -f 3.

Offline

#616 2009-10-28 17:10:00

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Post your handy self made command line utilities

Daenyth wrote:

Odd. Where are those errors coming from? Looks like it's the contents of your mpd.log file. Do you rotate it often? Any crashes lately? Try adding something and running mpc update.

You're right... I failed. smile

Offline

#617 2009-10-29 19:39:49

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

lolilolicon wrote:
while sleep 1 ; do echo -ne '\033]2;'`date`'\007'; done &

turns your xterm/urxvt window title into a clock

thats pretty usefull, i have added it to my bash rc so all my terminals have the time in the title bar now


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#618 2009-11-02 11:08:48

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Post your handy self made command line utilities

Usefull for creating vim colorschemes for 256-color terminals

#!/bin/bash

for i in {16..255}; do 
    echo -en "\e[38;5;${i}mColor $i\t"
    [ $((++j%6)) -eq 0 ] && echo
done

Offline

#619 2009-11-02 16:31:40

tomd123
Developer
Registered: 2008-08-12
Posts: 565

Re: Post your handy self made command line utilities

A simple python script for checking and removing duplicate mp3 songs based on the id3 tag, artist and title. At the end it removes the duplicates leaving one copy. This is how I cleaned out 30GiB worth of music over the weekend lol

Make sure to change the path and trash directories. (i don't use a trash directory, but I wanted to check if this script wouldn't remove all my music files smile It uses pyid3lib from the repos. As far as I can tell, this worked for me, but this was written quickly so you might want to double check and send in some patches if you find something/ make it better smile

#!/usr/bin/python
import os
import pyid3lib
import shutil

path = "/home/tom/backup/siradio/"
trash = '/home/tom/trash/'
contents = os.listdir(path)

# table format
# path / artisttitle / marked for deletion
db = [None] * len( contents )
for i in range( len( contents ) ):
        tag = pyid3lib.tag( path + contents[i] )
        artisttitle = contents[i]
        # handle bad tags
        try:
                artisttitle = tag.artist + tag.title
        except:
                pass
        # fill table with contents
        db[i] = [contents[i], artisttitle, '']

for i in range( len( db ) ):
        for j in range( i + 1, len( db ) ):
                # check if artisttitle string is equal
                if db[i][1] == db[j][1]:
                        # mark for deletion
                        db[j][2] = 'd'

for i in range( len( db ) ):
        if db[i][2] == 'd':
                shutil.move( path + db[i][0], trash )

Offline

#620 2009-11-02 19:52:30

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: Post your handy self made command line utilities

I normally use RCS to edit most files, but sometimes I just want a quick backup of a file.
This is in my .bashrc file.

bu () { cp $1 ~/Backups/${1}-`date +%Y%m%d%H%M`.backup ; }

Called with "bu somefile" it puts a timestamped copy of whatever file in my Backups directory.


Here is one I use to get directory sizes in my current directory

dirsize ()
{
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
egrep '^ *[0-9.]*M' /tmp/list
egrep '^ *[0-9.]*G' /tmp/list
rm /tmp/list
}

I'm sure it could be tweaked a bit, but it does all I want it to wink
Not sure where I got that one, I did not write it.

This one greps by paragraph

grepp ()
{
perl -00ne "print if /$1/i" < $2
}

This one finds stuff in my history file

hs() {
history | grep ${1} | uniq --skip-fields=1 | sort -biz | uniq --skip-fields=2
}

This one makes using the bash shell easier for calculations

calc () { echo "scale=4; $1" | bc ; }

Someday I'll go into my whole .bashrc/.profile setups, but these are some of the things I thought some might find useful.

Offline

#621 2009-11-02 20:37:14

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Post your handy self made command line utilities

crouse wrote:

I normally use RCS to edit most files, but sometimes I just want a quick backup of a file.
This is in my .bashrc file.

bu () { cp $1 ~/Backups/${1}-`date +%Y%m%d%H%M`.backup ; }

Called with "bu somefile" it puts a timestamped copy of whatever file in my Backups directory.

I think it is best to quote your variable here. Or else it will break if the filename has a space.

bu () { cp "$1" ~/Backups/"${1}"-`date +%Y%m%d%H%M`.backup ; }

Offline

#622 2009-11-03 21:29:51

dunkelstern
Member
From: Augsburg, Germany
Registered: 2007-02-08
Posts: 68
Website

Re: Post your handy self made command line utilities

One of the most helpful scripts I use is "forcemount"
It is used if you have a disk image including partition tables and stuff and just want to mount the first partition of it no matter what.
The script just tries to mount the image and if that doesn't work skips some bytes forward and tries again. Useful for mounting full disk dd images or some types of virtual machine images directly:

#!/bin/bash

if [ "$1" = "" ] || [ "$2" = "" ] ; then
        echo "Usage: $0 <file> <mountpoint>" >&2
        exit 1
fi

for (( i=0; $i < 10000; i=$i + 1 )); do
   mount -o loop,offset=$(($i*512)) $1 $2 2>/dev/null >/dev/null && break
done

Offline

#623 2009-11-04 14:47:28

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

hey dunkelstern nice script.

one tip,

if [ $# -lt 2 ]; then
    echo "Usage..."
    exit 1
fi

Offline

#624 2009-11-04 23:02:18

kourosh
Member
From: England
Registered: 2009-03-10
Posts: 241
Website

Re: Post your handy self made command line utilities

My old packages checking script for conky like stopped working :S ah well, i threw together a new one in like a minute:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import string

check="pacman -Quq"
pkgs=os.popen(check)

count=0

for i in pkgs:
  count=count+1

if count==0:
  print "0 new packages"
elif count==1:
  print "1 new package"
else:
  print str(count)+" new packages"

Offline

#625 2009-11-05 10:36:28

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: Post your handy self made command line utilities

Not a script per say but a couple of useful aliases. Works like a very simple pushd and popd in bash. Only difference is that this one only works with one directory and it is global across all terminals.

I often have a project in a directory and open a couple of urxvts, one for coding, one for building. I simply cd into the project dir, do a pud and then in the other urxvt do a pod. Saves typing.

alias pud='pwd > ~/.dir'       #push directory
alias pod='cd $( cat ~/.dir )' #pop directory

I know there has to be a better way to do this but this is nice and simple and works for me.

Offline

Board footer

Powered by FluxBB