Posts Tagged ‘ Linux

Bash script template with parameter evaluation

just a handy bash script template:

#!/bin/bash

scriptname="script_template"

### functions
function usage
{
    echo -e "usage: $scriptname MANDATORY [OPTION]\n"
    echo -e "MANDATORY mandatory parameter:"
    echo -e "  -m,  --mandatory  VAL  The desc of the mandatory parameter\n"
    echo -e "OPTION optional parameter:\n"
    echo -e "  -h,  --help            Prints this help"
    echo -e "  -o1, --optional1       The optional1 parameter"
    echo -e "  -o2, --optional2 VAL   The optional2 parameter\n"
    echo -e "EXAMPLE:"
    echo -e "  $scriptname -m mandatory -o1 opt1"
}

# more...
#####

### Main

if [ $# == 0 ]; then
    echo "Called with no parameter!"
    usage
    exit 1
fi

mand=
opt1="false" # or use 1 and 0, with default 0
opt2="defaultValue"

# parameter while-loop
while [ "$1" != "" ];
do
    case $1 in
   -m  | --mandatory )    shift
                          mand=$1
                ;;
   -o1 | --optional1 )    opt1="true"
                          ;;
   -o2 | --optional2 )    shift
                          opt2=$1
                ;;
   -h  | --help )         usage
                          exit
                ;;
   *)                     usage
                          echo "The parameter $1 is not allowed"
                          exit 1 # error
                ;;
    esac
    shift
done


if [ "$mand" == "" ]; then
    echo "mandatroy parameter is missing"
    usage
   
    exit 1 # error
fi

echo "params: $mand, $opt1, $opt2"
#####

A paper made tux

Actually, I really have to learn for my exam ... but then I found this:

But I think 15 minutes are indeed very optimistic - I took an hour or so. Here is my result of tux:

A fuzzyclock for the bash (german)

Last weekend I've got some time to do some funny stuff. A friend of mine asked me if I know a script which displays a fuzzyclock in the bash. To refresh my bash skills, I took the time and "hacked" (a bit dirty) this for him. The script displays the current time as written german words ... see the following screenshot:fuzzyclock_screenshot
If you are interested, here is the script: fuzzyclock_v0.1.tar.gz
For feedback or improvements, please leave a comment.

Setting up Dropbox in an KDE environment

Dropbox is an online storage service. It is free and provides you 2 GB of space (for free). Dropbox synchronizes one specific folder on your filesystem - with the counterpart on the Dropbox servers (... it is actually a Amazon S3 system). The good thing: they also have an implementation for Linux. The normal linux-client runs in the background and observes the folder you have selected to sync with the online one.

Here are the steps to get it running and automatically started during your KDE session login:
- register on getdropbox.com
- download and install the (closed sources) binaries:

# change to home
$ cd ~

# download dropbox x86
#   for x86_64 http://www.getdropbox.com/download?plat=lnx.x86_64
$ wget -O dropbox.tar.gz http://www.getdropbox.com/download?plat=lnx.x86

# untar
$ tar xzf  dropbox.tar.gz

# run dropboxd (first time - wirzard is starting)
$ .dropbox-dist/dropboxd

# start dropbox during login
$ ln -s $HOME/.dropbox-dist/dropboxd .kde/Autostart/dropboxd

Dropbox also uses the KDE Notification-System to display status message of the Dropbox-folder.

More informations:

  • To Install Dropbox In An Entirely Text Based Linux Environment (Dropbox running as service) here
  • Wikipedia-Article here