Tag Archives: Bash

Copy all mp3 files in Music folder to USB dribe

Copying all mp3 files from my Music folder to a USB drive is pretty easy on my Macbook:

find Music -name *.mp3 -exec cp {} /Volumes/SANDISK \;

Consume locally build software without overloading your $PATH

How do you consume locally build software? For a while now i have used the following approach:

  • Create a ~/bin folder
  • Add that ~/bin folder to my $PATH
  • Add symlinks from binary to ~/bin (ln -s ~/src/git-tfs/GitTfs.Vs2010/bin/debug/git-tfs.exe git-tfs)

Please let me know about your strategy..

Restore from a MySQL dumpfile

If you are a longtime user of mysqldump you may have experienced that restoring with mysql < dumpfile doesn’t always work because of referential problems. Here is a little script that takes care of it: mysql-restore.txt.

Backup script

The current shell server i’m using returns bogus output for commands like df. Mind the negative value for 1-k blocks.

timvw@localhost:~$ df

Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda1 -780429856382 1 0 74% /

It thought it would be a good idea to have a backup once in a while, but most of the times when i did it, i forgot to backup my database. So i wrote a little backup.script that remembers to do that for me.

#!/bin/bash
###############################################################################
# Generate a backup file of homedirectory and database
# Author: Tim Van Wassenhove <timvw@users.sourceforge.net>
# Update: 2005-09-16 01:56:00
###############################################################################
# dump database
mysqldump -u username -ppassword -h invalid.org dbname > ~/mysql.dmp

# generate gzipped archive of homedirectory
tar -czf /tmp/backup.tgz ~

# move backup to homedirectory and change name
mv /tmp/backup.tgz ~/madoka-`date +%F`.tgz

# remove database dump
rm ~/mysql.dmp

Listen to online radio

#!/bin/sh
#
# Author: Tim Van Wassenhove <timvw@users.sourceforge.net>
# Update: 2004-05-21 02:50:31
#
# This script allows you to listen to Belgian online radio streams.
#

if [ "$1" == "" ]; then
echo "
[1]   Radio 1
[2]   Radio 2
[3]   Studio Brussel
[4]   Donna
[5]   4FM
[6]   QMusic
[7]   Topradio
[9]   Klara

Enter your choice: "
read choice
else
choice="$1"
fi

case "$choice" in
    1) station="mms://streampower.belgacom.be:1755/radio1high" ;;
    2) station="mms://streampower.belgacom.be:1755/ra2vlbhigh" ;;
    3) station="mms://streampower.belgacom.be:1755/stubruhigh" ;;
    4) station="mms://streampower.belgacom.be:1755/donnahigh" ;;
    5) station="mms://mss.streampower.be/4fmhi" ;;
    6) station="mms://mss.streampower.be/qmusic_ahi" ;;
    7) station="mms://mss.streampower.be/topahi" ;;
    9) station="mms://streampower.belgacom.be:1755/stubruhigh" ;;
    *) echo "Wrong choice!"
    exit
esac

mplayer $station

exit

Kill a user and his processes

#!/bin/sh
#
# Author: Tim Van Wassenhove
# Update: 12-12-2003 13:15
#
# This script kills all processes that are owned by a given user.
#

if [ -n "1" ]
then
        ps -ef | grep $1 | grep -v grep | awk ‘{ print }’ | xargs kill -9
else
        echo "Usage: killuser.sh username"
fi