Home > Bash, Programming, Tip > Simple bash reminder

Simple bash reminder

Need to have a reminder while working on the computer? I have developed this simple but very useful script to remind me things that I would forget without a reminder.

#!/bin/bash
# Simple reminder shell script
usage() {
 echo -e "usage: `basename $0` [-t minutes] [-m message] [-b beeps]"
 echo -e "-t M\t\ttime scheduled to go off in minutes, default 1"
 echo -e "-m message\t\tMessage to show when alarm goes off, \
default to 'Something needs your attention'"
 echo -e "-b beeps\t\tNumber of beeps, default 5"
}

alarm() {
    sleep ${1}m
    echo -n ${2}
    bps=$3
    seq_beeps=$((bps*2))
    for i in `seq $seq_beeps`; do
        [ `expr $i % 2` == 0 ] && sleep 1 || echo -n -e \\a
    done
}

minutes=1
beeps=5
msg='Something needs your attention'
[ ! `whoami` == "root" ] && echo \
    "must be root to run this script" && exit 0
while getopts "t:m:b:h" flag
do
    case $flag in
        t)
            case $OPTARG in

                 [0-9] | [0-9][0-9] | [0-9][0-9][0-9] )
                minutes=$OPTARG;;

                *)
                echo "usage: minutes value must be in range 0 to 999"
                ;;
            esac
            ;;
        m)
            msg=$OPTARG;;
        b)
            case $OPTARG in
                 [0-9] | [0-9][0-9])
                    beeps=$OPTARG
                    ;;
                *)
                    echo 'usage: beeps value must be in range 0 to 99'
                    ;;
            esac
            ;;
        h|*)
            usage
            exit 0
            ;;
    esac
done
alarm $minutes "$msg" $beeps &

Example Usage:

alarm -t 5 -m "Check your coffee" -b 10
NOTE: You have to use sudo or become root to use this script.

Advertisements
Categories: Bash, Programming, Tip
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: