Scripting

A EXIF dater script

The script below will take a filename eg: DSCN0001.JPG, extract the “Image Created” metadata and rename the original file to something like 2006-03-23_DSCN00001.JPG and it will do it automatically for you. #! /bin/shfunction usage() {if [ $# -ne 1 ]; then    echo “ExifDater – version 0.1 – March 23 2006”    echo “El-Lotso ” […]

Read More
Linux

Strip comments from config files

This is at short script to strip/remove comments from config files #!/bin/bash # Code to cat a config file removing all comments and blank lines. grep -vh ‘^[[:space:]]*#’ “$@” | grep -v ‘^$’ Usage: ./confcat.sh /etc/make.conf Alternativ is to use sed cat filename | sed -e ‘s/#.*//;/^\s*$/d’ “$@” This also strips comments at the end […]

Read More
Scripting

Root Check

Sometime it is useful to determine if a script is being run as root or not. A simple check can be performed at the start of a script before anything important is done. The bit of code below will do this. # Check the script is being run by root if [ “$(id -u)” != […]

Read More
Linux

Bash misc tips

Bash debugging A nice thing to do is to add on the first line #!/bin/bash -x This will produce some interesting output information Reading user input with read In many ocations you may want to prompt the user for some input, and there are several ways to achive this. This is one of those ways: […]

Read More
Linux

Bash user interfaces

Using select to make simple menus #!/bin/bash OPTIONS=”Hello Quit” select opt in $OPTIONS; do if [ “$opt” = “Quit” ]; then echo done exit elif [ “$opt” = “Hello” ]; then echo Hello World else clear echo bad option fi done If you run this script you’ll see that it is a programmer’s dream for […]

Read More